You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently local state is preserved when navigating between two instances of the same route with different path params, i.e. navigating from /posts/1 to /posts/2. In our app we want to treat path param changes as completely new instances of the page with forced remounts, like if we were using <PostPage key={params.postId} /> at the top level. There's currently no mechanism for opting into this behavior.
The way we mentally think about our routes is that path params take you to a new page, while search params configure the current page. So the mechanism has to allow for search params to change without remounting as well. We were surprised to find that navigating /posts/1 => /posts/2 we ended up in a different state than when navigating /posts/1 => / => /posts/2.
I was bittten by the exact some problem just now. I think simply having a callback method on createRoute (and similar APIs) which should return a key which causes a full remount if changes should be good.
Which project does this relate to?
Router
Describe the bug
This issue is a result from a discussion I had with @schiller-manuel in https://discord.com/channels/719702312431386674/1316448877670563931.
Currently local state is preserved when navigating between two instances of the same route with different path params, i.e. navigating from
/posts/1
to/posts/2
. In our app we want to treat path param changes as completely new instances of the page with forced remounts, like if we were using<PostPage key={params.postId} />
at the top level. There's currently no mechanism for opting into this behavior.The way we mentally think about our routes is that path params take you to a new page, while search params configure the current page. So the mechanism has to allow for search params to change without remounting as well. We were surprised to find that navigating
/posts/1 => /posts/2
we ended up in a different state than when navigating/posts/1 => / => /posts/2
.Your Example Website or App
https://stackblitz.com/edit/tanstack-router-kgrqvrxv?file=src%2Froutes%2Fposts.%24postId.tsx
The text was updated successfully, but these errors were encountered: