T
TanStack4w ago
genetic-orange

How do I make search params optional in navigate()?

Getting the attached error for a route declared like this:
const SearchSchema = z.object({
page: z.coerce.number().int().min(1).max(9999).default(1),
pageSize: z.coerce.number().int().min(1).max(100).default(20),
});

export const Route = createFileRoute("/_app/taxa/drafts")({
validateSearch: (s) => SearchSchema.parse(s),
const SearchSchema = z.object({
page: z.coerce.number().int().min(1).max(9999).default(1),
pageSize: z.coerce.number().int().min(1).max(100).default(20),
});

export const Route = createFileRoute("/_app/taxa/drafts")({
validateSearch: (s) => SearchSchema.parse(s),
Is there something I'm not doing to enforce that the search params are optional on this route? I've tried also adding optional() to the zod schema, but it doesn't change anything, nor does (s?) as a validateSearch arg, or SearchSchema.parse(s ?? {}).
No description
1 Reply
deep-jade
deep-jade3w ago
pass the schema directly
export const Route = createFileRoute("/_app/taxa/drafts")({
validateSearch: SearchSchema
export const Route = createFileRoute("/_app/taxa/drafts")({
validateSearch: SearchSchema

Did you find this page helpful?