T
TanStack16mo ago
correct-apricot

Redirect behaviour on child pages

Hello! I am having some trouble with redirects in Tanstacak Router. I basicly have some pages set up something like this:
/dashboard
/dashboard
/dashboard/user
/dashboard/user
/dashboard/admin
/dashboard/admin
It is not the exact setup, but for this problem it does not matter. The
/dashboard
/dashboard
pages does not have any content, other than a simple div with some simple styling (To apply to all child pages) and an outlet. I do not want anyone to visit the
/dashboard
/dashboard
page since it does not have any real content. I therefore want to redirect the user to
/dashboard/user
/dashboard/user
. I have tried to throw a redirect:
throw redirect({
to: "/dashboard/user",
});
throw redirect({
to: "/dashboard/user",
});
Within the beforeLoad, load, and onEnter methods of the route. But either nothing happens, or when the redirect happens, nothing renders on the new page (Even if I refresh). I understand this is probably something to do with an infinite loop, since it always renders "/dashboard", and therefore redirects. Even if I am on the child pages. Does anyone know what I have to do?
1 Reply
correct-apricot
correct-apricotOP16mo ago
If I use the Navigate component to navigate to "/dashboard/user", all pages from "/dashboard/" and its child routes, even "/dashboard/admin" redirects to "/dashboard/user"

Did you find this page helpful?