TanStack Router provides first-class support for validating search parameters using popular validation libraries. This ensures your URL state is type-safe and validated at runtime.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tanstack/router/llms.txt
Use this file to discover all available pages before exploring further.
Why Validate Search Params?
Search parameters come from the URL and are inherently untyped strings. Validation helps you:- Ensure type safety - Convert and validate URL strings to typed values
- Prevent runtime errors - Catch invalid data before it reaches your components
- Improve developer experience - Get autocomplete and type checking for search params
- Transform data - Convert strings to numbers, booleans, dates, and complex objects
How Validation Works
When you define a route with search parameter validation, TanStack Router:- Parses the URL search parameters as strings
- Passes them through your validator
- Transforms the data according to your schema
- Provides fully typed search params to your components
Supported Validation Libraries
TanStack Router provides official adapters for the most popular validation libraries:Zod
The most popular TypeScript-first schema validation library
Valibot
Lightweight, modular validation library with excellent TypeScript support
ArkType
Runtime validation with TypeScript-like syntax
Installation
Each validation adapter is published as a separate package. Install the one that matches your validation library:Basic Usage
All validation adapters follow the same pattern:- Import the validator function from the adapter package
- Pass your schema to the validator
- Use the validator in the
validateSearchoption of your route
Validation Behavior
When validation fails, TanStack Router will:- Prevent navigation to the route
- Preserve the current route state
- Throw a validation error that you can catch and handle
Type Inference
The validation adapters automatically infer TypeScript types from your schemas. This means:useSearch()returns fully typed search params<Link>components enforce correct search param types- Navigation functions require valid search params
Next Steps
Choose a validation library to get started:- Zod Adapter - Most popular, comprehensive features
- Valibot Adapter - Lightweight and modular
- ArkType Adapter - TypeScript-like syntax