T
TanStack2mo ago
metropolitan-bronze

relative navigation with dynamic source route?

I have a utility that makes the concept of a "Search Route" which basically allows things like modals or other widgets to be tied to a search param. I have this following function i use to either open or close the route. the goal is basically i want the router to preserve it's current page, but i just want to modify the search params:
function go(k: string, v?: unknown) {
void navigate({
to: ".",
search: (prev) => ({ ...prev, [k]: v }),
});
}
function go(k: string, v?: unknown) {
void navigate({
to: ".",
search: (prev) => ({ ...prev, [k]: v }),
});
}
previously this worked really well, but i recently migrated to the newer devinxi version and now it consistently navigates to the homepage after re-reading the docs, I guess this sort of makes sense- although it claims every navigation is relative, which I sort if interpreted as if the above should work, it also mentions that if no from attr is provided then it will navigate from the root route, so . will take me to / is there anyway to do what i'm trying to do above? the search params as is start yelling at me if i remove to , presumably because it can't ensure that k is a valid search key for any route
3 Replies
metropolitan-bronze
metropolitan-bronzeOP2mo ago
actually just found the docs section that i must've initially read
If you want to update the search params in a generic component that is rendered on multiple routes, specifying from can be challenging.

In this scenario you can set to="." which will give you access to loosely typed search params.
If you want to update the search params in a generic component that is rendered on multiple routes, specifying from can be challenging.

In this scenario you can set to="." which will give you access to loosely typed search params.
though this isn't working for me right now. "." is always bringing me to the "/" route
extended-salmon
extended-salmon2mo ago
open issue, will be fixed soon https://github.com/TanStack/router/issues/4526
GitHub
Regression: navigate({ to: "." }) redirects to base path after upda...
Which project does this relate to? Router Describe the bug After updating @tanstack/react-router from version 1.120.13 to 1.121.34, I encountered a regression when navigating with navigate({ to: &q...
metropolitan-bronze
metropolitan-bronzeOP2mo ago
oh ok! thank you

Did you find this page helpful?