Skip to content
API/parseSearch()

parseSearch()

function
src/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 { parseSearch } from '@qubeejs/react/tanstack-router';
function parseSearch(searchStr: string): Record<string, string | string[]>
Parameter Type Description
searchStr string The query string, with or without its ?

The search object the router hands to its routes

const router = createRouter({ parseSearch, routeTree, stringifySearch });