@@ -13,9 +13,9 @@ import { createFileRoute } from '@tanstack/react-router'
1313import { z } from ' zod'
1414
1515const productSearchSchema = z .object ({
16- page: fallback ( z .number (), 1 ).default (1 ),
17- category: fallback ( z .string (), ' all' ).default (' all' ),
18- showSale: fallback ( z .boolean (), false ).default (false ),
16+ page: z .number (). default ( 1 ).catch (1 ),
17+ category: z .string (). default ( ' all' ).catch (' all' ),
18+ showSale: z .boolean (). default ( false ).catch (false ),
1919})
2020
2121export const Route = createFileRoute (' /products' )({
@@ -100,7 +100,6 @@ Start by identifying what search parameters your route needs:
100100
101101``` tsx
102102import { z } from ' zod'
103- import { fallback } from ' @tanstack/zod-adapter'
104103
105104const shopSearchSchema = z .object ({
106105 // Pagination
@@ -238,7 +237,7 @@ const dashboardSchema = z.object({
238237 status: z .enum ([' active' , ' inactive' ]).optional (),
239238 type: z .string ().optional (),
240239 })
241- .default ({}),
240+ .prefault ({}),
242241})
243242```
244243
@@ -333,7 +332,7 @@ export const Route = createFileRoute('/example')({
333332
334333### Problem: Search Parameters Cause TypeScript Errors
335334
336- ** Cause:** Missing or incorrect schema definition with Zod v3 .
335+ ** Cause:** Missing or incorrect schema definition.
337336
338337** Solution:** Ensure your schema covers all search parameters and use proper types:
339338
@@ -345,12 +344,12 @@ export const Route = createFileRoute('/page')({
345344
346345// ✅ Complete schema with proper validation
347346const searchSchema = z .object ({
348- page: fallback ( z .number (), 1 ).default (1 ),
349- category: fallback ( z .string (), ' all' ).default (' all' ),
347+ page: z .number (). default ( 1 ).catch (1 ),
348+ category: z .string (). default ( ' all' ).catch (' all' ),
350349})
351350
352351export const Route = createFileRoute (' /page' )({
353- validateSearch: zodValidator ( searchSchema ) ,
352+ validateSearch: searchSchema ,
354353 component: MyPage ,
355354})
356355```
@@ -382,7 +381,7 @@ const schema = z.object({
382381``` tsx
383382const schema = z .object ({
384383 // Required with default (navigation can omit, but always present in component)
385- page: fallback ( z .number (), 1 ).default (1 ),
384+ page: z .number (). default ( 1 ).catch (1 ),
386385
387386 // Truly optional (can be undefined in component)
388387 searchTerm: z .string ().optional (),
@@ -397,8 +396,8 @@ const schema = z.object({
397396
398397``` tsx
399398const schema = z .object ({
400- filters: fallback (
401- z .object ({
399+ filters: z
400+ .object ({
402401 status: z .enum ([' active' , ' inactive' ]).optional (),
403402 tags: z .string ().array ().optional (),
404403 dateRange: z
@@ -407,9 +406,9 @@ const schema = z.object({
407406 end: z .string ().pipe (z .coerce .date ()),
408407 })
409408 .optional (),
410- }),
411- {},
412- ). default ({}),
409+ })
410+ . prefault ({})
411+ . catch ({}),
413412})
414413```
415414
0 commit comments