Skip to content

How to use completely optional search params? #923

Discussion options

You must be logged in to vote

(I don't know if I understand your problem correctly. If not, please create a minimal reproducer.)

You can tag the param type of a search validation function using SearchSchemaInput.

see this example:
https://github.com/TanStack/router/blob/main/examples/react/basic-default-search-params/src/main.tsx#L149

and the docs:
https://tanstack.com/router/v1/docs/api/router/RouteOptionsType#validatesearch

In your case, you could have only optional properties like this:

 validateSearch: (
    input: {
      foo?: string
      bar?: 'string'
    } & SearchSchemaInput,
  ) => ...

Then when navigating to that page, the search prop will not be required anymore.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@danieljmann96
Comment options

@chidimo
Comment options

Answer selected by danieljmann96
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants