How to use navigate but keep prev search params? #3345
Unanswered
ruiaraujo012
asked this question in
Q&A
Replies: 2 comments 5 replies
-
Beta Was this translation helpful? Give feedback.
1 reply
-
what does that mean? can you please provide a complete minimal example by forking one of the existing stackblitz examples and provide exact steps that a user would perform? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
Let's assume the following routes:
/users
/users/$userId
/notifications
I need to implement a back button, so the user could navigate back in the app. To go from
/users/1
I could use aLink
ornavigate
withto='..'
, and it works, but, if I have search params, those will be lost in the process, for example:/users?page=5&size=10
I select one user and navigate to/users/273
/users?page=0&size=10
(search params reset to default ones)I could use
history.back()
, although, if I came from/notifications
I don't want to go back there, but to/users?page=0&size=10
How can I solve this? Is there any way of knowing the
from
route so I could usehistory.back()
orto='..'
conditionally?Here is the example https://stackblitz.com/edit/tanstack-router-8jslocus?file=src%2Froutes%2Fusers%2F%24userId.tsx
Steps:
Next
a couple of times (like page=3)Navigate example to some user
Back
(prev search was lost, I could usehistory.back()
, but...)here
Back
(this back should go tousers
with the default search)So I wanted to conditionally use
history.back()
or navigateto='..'
based on the last route, if users, go back to preserve search, otherwise, use theto
option.Beta Was this translation helpful? Give feedback.
All reactions