T
TanStack3y ago
quickest-silver

Simple Example Using Navigate And Search Params

Given a validateSearch object like this:
validateSearch: () => z.object({
stopRedirect: z.boolean().optional()
}),
validateSearch: () => z.object({
stopRedirect: z.boolean().optional()
}),
How should I call navigate? Calling navigate like so:
navigate({
....
search: {
stopRedirect: false,
},
})
navigate({
....
search: {
stopRedirect: false,
},
})
gives an errors saying: Type '{ shouldRedirect: false; }' is not assignable to type 'SearchReducer... Following the Code Sandbox more closely, I try this:
search: (old) => {
return {
...old,
stopRedirect: true,
}
},
search: (old) => {
return {
...old,
stopRedirect: true,
}
},
I get an error saying: Type 'undefined' is not assignable to type '() => { shape: { stopRedirect: ZodOptional<ZodBoolean>; }; keys: string[]; }'.
3 Replies
quickest-silver
quickest-silverOP3y ago
Is it possible because I'm navigating from one route to another? The navigate call is not from a child route
quickest-silver
quickest-silver3y ago
Currently, when validating the query params with zod, you need to call the parse method on the ZodObject passing into it the search params from the router.
const route = new Route({ ...config,
validateSearch: (search) => z.object({
stopRedirect: z.boolean().optional()
}).parse(search)
});
const route = new Route({ ...config,
validateSearch: (search) => z.object({
stopRedirect: z.boolean().optional()
}).parse(search)
});
quickest-silver
quickest-silverOP3y ago
Makes sense, thank you Sean

Did you find this page helpful?