#Default search which is always defined
12 messages · Page 1 of 1 (latest)
Schema validators usually have a "default value" method. For example w/ zod it's { foo: z.string().default('bar') }
(not all of them have this, i think yup doesn't for example)
if you use that in the validateSearch of your route, then the search param is not required (navigations to the path don't require search params) and useSearch has it defined (useSearch always returns a defined value)
@spare ruin yes, but how to do it without a validator?
I would have expected that inside validateSearch, assigning a default value would solve this issue. it doesn't (navigation still requires search), unless I'm doing something wrong
sorry idk how you do it without a validator
just tried this
validateSearch: ({hello}: {hello?: string}) => ({
hello: hello ?? 'world',
}),
and it doesn't work. Might be a bug... not sure
it's all documented 🙂
The RouteOptions type is used to describe the options that can be used when creating a route. RouteOptions properties The RouteOptions type accepts an object with the following properties: getParentRo...
Optionally, the parameter type can be tagged with the SearchSchemaInput type like this: (searchParams: TSearchSchemaInput & SearchSchemaInput) => TSearchSchema. If this tag is present, TSearchSchemaInput will be used to type the search property of <Link /> and navigate() instead of TSearchSchema. The difference between TSearchSchemaInput and TSearchSchema can be useful, for example, to express optional search parameters.