API/parseSearch()
parseSearch()
functionsrc/utils/plain-search.ts1 parameter
Read a query string as plain text, for the parseSearch option of a TanStack Router.
TanStack Router’s own serialisers read every value as JSON and write it back, so a list’s
query does not survive them: 10 lands as 10, "react hooks" loses its quotes, 1.50
becomes 1.5. With this function and stringifySearch, every value stays the string it
is in the URL, and a name that repeats is a list of strings.
Every search value of the app is then a string: a route whose validateSearch wants a number
has to coerce it.
Import
Section titled “Import”import { parseSearch } from '@qubeejs/react/tanstack-router';Signature
Section titled “Signature”function parseSearch(searchStr: string): Record<string, string | string[]>Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
searchStr |
string |
The query string, with or without its ? |
Returns
Section titled “Returns”The search object the router hands to its routes
Example
Section titled “Example”const router = createRouter({ parseSearch, routeTree, stringifySearch });