router: Default search params from validateSearch do not populate the URL
Describe the bug
When using validateSearch, if you return a default value it becomes available via the useSearch hook in a component, but it does not appear in the URL.
Your Example Website or App
https://stackblitz.com/edit/github-cqxxd6?file=src%2Froutes%2Fabout.tsx
Steps to Reproduce the Bug or Issue
- Click on the ‘about’ link
Expected behavior
The default parameter from validateSearch is available via useSearch but does not show in the URL search params.
Screenshots or Videos
No response
Platform
- OS: Windows
- Browser: Chrome, Edge
Additional context
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 12
- Comments: 15 (6 by maintainers)
Another related issue I noticed, is that the
<Link>throws a typescript error, thatalthough all search params use
optionalfrom zod:@MariuzM you need to tag the input type with
SearchSchemaInputsee https://tanstack.com/router/latest/docs/framework/react/api/router/RouteOptionsType#validatesearch-method
or use one of the search schema validators listed here
https://tanstack.com/router/latest/docs/framework/react/guide/search-params#adapters
@allan-cannon please create a new issue and include a complete minimal example
This issue still happens for me. The different behaviour is strange. @schiller-manuel Have you maybe had the chance to look into this further?
I found something else that I find strange.
Shouldn’t
const search = useSearch({ from: null! })andconst searchFromLocation = useLocation({ select: (l) => l.search })always return the same thing?searchFromLocationseems to mirror what is seen in the url andsearchseems to always show the correct fallbacks. Here is is quick reproduction stackblitz: https://stackblitz.com/edit/github-2gwkq9?file=src%2Froutes%2Fparams.tsx