Throwing redirect from beforeLoad or loader doesn't work as expected
Im trying to achieve sort of a landing route for my app, which would handle redirecting to the correct language route. Something like this:
-
/ redirects to /{defaultLanguage}, in my example /en
- /{invalidLanguage} redirects to /error
- /{validLanguage} doesn't redirect anywhere
I have tried to throw redirect in 6 different ways. In rootRoute, in / and in /$language. None of beforeLoad, loader or parseParams work in any of the routes.
I think there might be a bug in reactivity somewhere. Seems like beforeLoad or loader doesn't get the updated params after a redirect.
See the 6 different cases in my stackbliz, uncomment them one by one
https://stackblitz.com/edit/tanstack-router-hday5z?file=src%2Fmain.tsx
Please tell me if I can do anything to explain the issue better, I'm having some trouble wrapping my head around this :)Joonas Tiala
StackBlitz
TS Router: throwing redirects - StackBlitz
Run official live example code for Router Basic, created by Tanstack on StackBlitz
1 Reply
vicious-gold•3y ago
Fixing this now