Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No builtin mechanism for remounting on path param changes #2990

Open
jakst opened this issue Dec 12, 2024 · 1 comment
Open

No builtin mechanism for remounting on path param changes #2990

jakst opened this issue Dec 12, 2024 · 1 comment

Comments

@jakst
Copy link
Contributor

jakst commented Dec 12, 2024

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

@levrik
Copy link
Contributor

levrik commented Dec 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants