TanStackT
TanStack2y ago
1 reply
ordinary-sapphire

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/user

/dashboard/admin

It is not the exact setup, but for this problem it does not matter.
The
/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
page since it does not have any real content. I therefore want to redirect the user to
/dashboard/user
.
I have tried to throw a redirect:
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?
Was this page helpful?