@@ -50,11 +50,9 @@ function ProductsPage() {
50
50
- ** Error Handling** : Built-in validation error management
51
51
- ** Maintainability** : Clear, declarative schema definitions
52
52
53
- ## Validation Library Options
53
+ ## Validation Library Setup
54
54
55
- TanStack Router supports any standard schema-compliant validation library. Choose the one that best fits your project:
56
-
57
- ### Zod (Most Popular)
55
+ TanStack Router supports any standard schema-compliant validation library. This guide focuses on Zod for examples, but you can use any validation library:
58
56
59
57
``` bash
60
58
npm install zod @tanstack/zod-adapter
@@ -75,61 +73,9 @@ export const Route = createFileRoute('/products')({
75
73
})
76
74
```
77
75
78
- ### Valibot (Lightweight Alternative)
79
-
80
- ``` bash
81
- npm install valibot @tanstack/valibot-adapter
82
- ```
76
+ ** For detailed validation library comparisons and advanced validation patterns, see:** [ Validate Search Parameters with Schemas] ( ./validate-search-params.md )
83
77
84
- ``` tsx
85
- import { valibotValidator , fallback } from ' @tanstack/valibot-adapter'
86
- import * as v from ' valibot'
87
78
88
- const searchSchema = v .object ({
89
- page: fallback (v .number (), 1 ),
90
- category: fallback (v .string (), ' all' ),
91
- })
92
-
93
- export const Route = createFileRoute (' /products' )({
94
- validateSearch: valibotValidator (searchSchema ),
95
- component: ProductsPage ,
96
- })
97
- ```
98
-
99
- ### Yup
100
-
101
- ``` bash
102
- npm install yup
103
- ```
104
-
105
- ``` tsx
106
- import * as yup from ' yup'
107
-
108
- const searchSchema = yup .object ({
109
- page: yup .number ().default (1 ),
110
- category: yup .string ().default (' all' ),
111
- })
112
-
113
- export const Route = createFileRoute (' /products' )({
114
- validateSearch : (search ) => searchSchema .validateSync (search ),
115
- component: ProductsPage ,
116
- })
117
- ```
118
-
119
- ### Custom Validation Function
120
-
121
- For complete control, implement your own validation:
122
-
123
- ``` tsx
124
- export const Route = createFileRoute (' /products' )({
125
- validateSearch : (search : Record <string , unknown >) => ({
126
- page: Number (search .page ) || 1 ,
127
- category: (search .category as string ) || ' all' ,
128
- showSale: Boolean (search .showSale ),
129
- }),
130
- component: ProductsPage ,
131
- })
132
- ```
133
79
134
80
## Step-by-Step Setup with Zod
135
81
@@ -470,8 +416,12 @@ const schema = z.object({
470
416
471
417
## Common Next Steps
472
418
473
- <!-- Uncomment when guides are available
419
+ After setting up basic search parameters, you might want to:
420
+
421
+ - [ Validate Search Parameters with Schemas] ( ./validate-search-params.md ) - Add robust validation with Zod, Valibot, or ArkType
474
422
- [ Navigate with Search Parameters] ( ./navigate-with-search-params.md ) - Learn to update search params with Links and navigation
423
+
424
+ <!-- Uncomment when guides are available
475
425
- [Handle Complex Search Parameter Types](./complex-search-param-types.md) - Work with arrays, objects, dates, and nested data
476
426
-->
477
427
0 commit comments