TanStackT
TanStack3y ago
10 replies
popular-magenta

Q: Regarding the sharing behaviour of query params between routes

My question is regarding the sharing of search query param values across path routes.

This is the route setup I've got.

rootRoute
| / - index.ts index route
| agreements - agreements.path.ts path
| / - agreements.index.ts index route of 'agreements'
| reservations - reservations.path.ts path
| / - reservations.index.ts index route of 'reservations'

Both the index routes of 'agreements' and 'reservations' have a validateSearch zod schema of:
z.object({ page: z.number(), obj: z.object({}).optional() })

and a preSearchFilters functions of on both index routes of 'agreements' and 'reservations':
{
  preSearchFilters: [(search) => ({...search, page: search?.page ?? 1 })]
}


Currently,
* if I am on /reservations?page=2
* and click on a link that ONLY has the following prop of to='/agreements' on <Link />
* it takes me to /agreements?page=2 instead of /agreements?page=1.

Q1: Is this expected behaviour?
Q2: To get it to go to /agreements?page=1 I should explicitly provide the following of to='/agreements' search={(s) => ({ ...s, page: 1 })} to <Link />?
Was this page helpful?