Purpose of `from` for JavaScript users
Hey 👋🏽 ,
I use tanstack-router in a JS project. Until now I have always tried to supply from in the navigations and then route relative. I.e.:
What do you recommend to JS users? The relative approach, or the absolute approach?
Thanks
4 Replies
foreign-sapphire•16mo ago
My current opinion is if you cannot reliably know that
from
will match the current location at runtime then use absolute to
because it's to a concrete.other-emeraldOP•16mo ago
Ok, do you have an example case, where from would not match the current location?
metropolitan-bronze•16mo ago
this can happen if you have component that is rendered on multiple routes
other-emeraldOP•16mo ago
Ah, sure, I didn't even think about that, because I always navigate in the route component.
So you can say that if you know where you are, you can prefer relative routing.
If you find yourself in a situation where you could pass from as a parameter (e.g. if you use redirect or useNavigate without a route), should you pass from or not?
I read here https://github.com/TanStack/router/issues/1665#issuecomment-2131384105 that from does not play a role in runtime. Is that the case? In my opinion, i.e. redirect does not ignore the provided
from
.