Validating URL Search Params in TanStack Start With Zod
Treating URL query parameters as trusted data causes pages to crash, show empty results, or send bad values to the API. TanStack Start addresses this by letting each route declare a validateSearch function that the router runs whenever the URL changes. Using a Zod schema with .catch() instead of .default() replaces invalid values such as a non-numeric page with safe defaults rather than raising errors. Components then read strongly typed search values through Route.useSearch(), without manual parsing or casting. Filters stored in the URL also survive page refreshes, can be shared as links, and respond to the back button.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in