Uh oh!
There was an error while loading. Please reload this page.
How to keep search parameters for links in breadcrumbs? #7902
Replies: 2 comments 1 reply
Breadcrumb links reset the params because a <Linkto="/legals"search={(prev)=>prev}>Legals</Link>
|
I checked this on The loss happens on the way in, not on the way back. The fix is It needs to sit on a route that's active for both navigations. The root route (or a shared parent layout route, if you'd rather scope it) works: import{createRootRoute,retainSearchParams}from'@tanstack/react-router'exportconstRoute=createRootRoute({validateSearch: (search)=>(search.page===undefined ? {} : {page: Number(search.page)}),search: {middlewares: [retainSearchParams(['page'])],},})Note the third line — with the middleware in place, a plain One trade-off to be aware of rather than discover later: Fair warning on what I did and didn't check: I reproduced the mechanism in a minimal router rather than running your sandbox, so the shape of the fix is verified but the exact wiring for your route tree may differ — particularly if |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
sandbox with code
Steps to reproduce:
open list2).2. Click buttonopen entityLegals listin breadcrumbs to navigate to previous pageLegals list) was resettedIs there a way to keep search parameters for links in breadcrumbs?
All reactions