Skip to content

Immediate redirect from parent to child #3464

Closed Answered by kiliman
jmaldon1 asked this question in Q&A
Discussion options

You must be logged in to vote

The issue is that when you navigate to a nested route like dashboard/plans, Remix is calling the parent loader dashboard in addition to the dashboard/plans loader. Since the parent is returning redirect, it gets caught in a loop. Perhaps Remix should detect this, but for now, here's a workaround:

// dashboard.tsx
export const loader: LoaderFunction = async ({ request }) => {
  const url = new URL(request.url);
  if (url.pathname === "/dashboard") {
    return redirect("/dashboard/plans");
  }
  return null;
};

Here, we're only redirecting if the current URL is /dashboard. When Remix calls loaders, it uses the current route and identifies the route id with ?data=route-id

So initial request…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@sergiodxa
Comment options

@jmaldon1
Comment options

@kiliman
Comment options

@caprica
Comment options

Answer selected by jmaldon1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants