Use this file to discover all available pages before exploring further.
The Valibot adapter enables type-safe search parameter validation using Valibot, a lightweight, modular validation library with excellent TypeScript support.
Import the valibotValidator function and pass it a Valibot schema:
import { createRoute } from '@tanstack/react-router'import { valibotValidator } from '@tanstack/valibot-adapter'import * as v from 'valibot'const invoicesRoute = createRoute({ getParentRoute: () => rootRoute, path: 'invoices', validateSearch: valibotValidator( v.object({ page: v.number(), filter: v.optional(v.string()), }), ),})
Now your search parameters are validated and typed:
function Invoices() { const search = invoicesRoute.useSearch() // search.page is number // search.filter is string | undefined return <div>Page {search.page}</div>}
import * as v from 'valibot'valibotValidator( v.object({ startDate: v.pipe(v.string(), v.isoDate()), endDate: v.pipe(v.string(), v.transform((str) => new Date(str))), }),)
Create custom validators with Valibot’s pipe system:
import * as v from 'valibot'// Custom validator for positive even numbersconst evenNumber = () => v.custom<number>( (value) => typeof value === 'number' && value % 2 === 0, 'Must be an even number', )valibotValidator( v.object({ count: v.pipe(v.number(), evenNumber()), }),)
When validation fails, Valibot throws a ValiError:
import * as v from 'valibot'// This will fail if page is not a valid numbervalibotValidator( v.object({ page: v.number(), }),)// Handle validation errorstry { // Invalid navigation attempt} catch (error) { if (error instanceof v.ValiError) { console.log('Validation errors:', error.issues) }}