You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the docs under Search Params it is noted that validation can be done via as:
// /routes/shop.products.tsx
type ProductSearchSortOptions = 'newest' | 'oldest' | 'price'
type ProductSearch = {
page: number
filter: string
sort: ProductSearchSortOptions
}
export const Route = createFileRoute('/shop/products')({
validateSearch: (search: Record<string, unknown>): ProductSearch => {
// validate and parse the search params into a typed state
return {
page: Number(search?.page ?? 1),
filter: (search.filter as string) || '',
sort: (search.sort as ProductSearchSortOptions) || 'newest',
}
},
})
Why would a check for page work if I input ?page=test? I do not see the value of this, this is rather defining optional search parameters with default values, but if I input ?sort='rating' this may crash depending on further code asserting that sort is only one of 'newest' | 'oldest' | 'price'. Am I wrong? Is this example showing something else?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
In the docs under
Search Params
it is noted that validation can be done viaas
:Why would a check for
page
work if I input?page=test
? I do not see the value of this, this is rather defining optional search parameters with default values, but if I input?sort='rating'
this may crash depending on further code asserting thatsort
is only one of'newest' | 'oldest' | 'price'
. Am I wrong? Is this example showing something else?Beta Was this translation helpful? Give feedback.
All reactions