Back preserving previous searchParams
I have a
/users
page that has pagination ie. /users?page=2
. I then have a details page at /user/<id>
eg /user/7
. I want to mirror the functionality of the browser and preserve that search param from the previous page with a custom "back" button on-page.
I've read the docs but can't find a clear way to do this — preferably using <Link>
if possible to keep it simple.2 Replies
plain-purple•16mo ago
pass
search={true}
to the Link 😉ratty-blushOP•16mo ago
Thank you @TkDodo 🔮 !
I was originally envisioning it working the same as the browser (ie. the search param is non-visible on the details page entirely) but after some thought; this would mean that anyone deep-linking to the page would not go "back" to the proper paginated spot.
I've realised I can use https://tanstack.com/router/latest/docs/framework/react/guide/route-masking to hide this search param but it's still "there" — this obviously though makes sharing links a worse experience as the pagination will be incorrect.
Seems like a tradeoff between a 'cleaner' url and a more shareable one!