Skip to main content Home Creators mehdibha dotui router-core-search-params
router-core-search-params validateSearch, search param validation with Zod/Valibot/ArkType adapters, fallback(), search middlewares (retainSearchParams, stripSearchParams), custom serialization (parseSearch, stringifySearch), search param inheritance, loaderDeps for cache keys, reading and writing search params.
Jump to install Skills Marketplace Discover and explore AI skills built by the community.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Copy promptShow prompt details A direct command skips the review prompt. Inspect the source before running it.
npx skills add https://github.com/mehdibha/dotUI --skill router-core-search-paramsThe command stays on one line. Scroll horizontally to inspect it before copying.
Prefer a local copy? Download the files currently available to SkillsMP.
Download Zip Downloading... More from this repository Install TanStack Devtools, pick framework adapter (React/Vue/Solid/Preact), register plugins via plugins prop, configure shell (position, hotkeys, theme, hideUntilHover, requireUrlFlag, eventBusConfig). TanStackDevtools component, defaultOpen, localStorage persistence.
Configure @tanstack/devtools-vite for source inspection (data-tsd-source, inspectHotkey, ignore patterns), console piping (client-to-server, server-to-client, levels), enhanced logging, server event bus (port, host, HTTPS), production stripping (removeDevtoolsOnBuild), editor integration (launch-editor, custom editor.open). Must be FIRST plugin in Vite config. Vite ^6 || ^7 only.
React bindings for TanStack Start: createStart, StartClient, StartServer, React-specific imports, re-exports from @tanstack/react-router, full project setup with React, useServerFn hook.
Related occupations SOC
Based on SOC occupation classification
name router-core/search-params description validateSearch, search param validation with Zod/Valibot/ArkType adapters, fallback(), search middlewares (retainSearchParams, stripSearchParams), custom serialization (parseSearch, stringifySearch), search param inheritance, loaderDeps for cache keys, reading and writing search params. type sub-skill library tanstack-router library_version 1.166.2 requires ["router-core"] sources ["TanStack/router:docs/router/guide/search-params.md","TanStack/router:docs/router/how-to/setup-basic-search-params.md","TanStack/router:docs/router/how-to/validate-search-params.md","TanStack/router:docs/router/how-to/navigate-with-search-params.md","TanStack/router:docs/router/how-to/share-search-params-across-routes.md","TanStack/router:docs/router/guide/custom-search-param-serialization.md"]
Search Params
TanStack Router treats search params as JSON-first application state. They are automatically parsed from the URL into structured objects (numbers, booleans, arrays, nested objects) and validated via validateSearch on each route.
CRITICAL : When using zodValidator() and Zod v3, use fallback() from @tanstack/zod-adapter, NOT zod's .catch(). Using .catch() with the zod adapter makes the output type unknown, destroying type safety. This does not apply to Valibot or ArkType (which use their own fallback mechanisms). It also does not apply to Zod v4, which should use .catch() and not use the zodValidator().
CRITICAL : Types are fully inferred. Never annotate the return of useSearch().
Setup: Zod Adapter (Recommended)
npm install zod @tanstack/zod-adapter
import { createFileRoute } from "@tanstack/react-router"
import { z } from "zod"
const productSearchSchema = z.object ({
page : z.number ().default (1 ).catch (1 ),
filter : z.string ().default ("" ),
sort : z.enum (["newest" , "oldest" , "price" ]).default ("newest" ).catch ("newest" ),
})
export const = ( )({
: productSearchSchema,
: ,
})
( ) {
{ page, filter, sort } = . ()
(
)
}
Route
createFileRoute
"/products"
validateSearch
component
ProductsPage
function
ProductsPage
const
Route
useSearch
return
<div >
<p >
Page {page}, filter: {filter}, sort: {sort}
</p >
</div >
Reading Search Params
In Route Components: Route.useSearch() function ProductsPage ( ) {
const { page, sort } = Route .useSearch ()
return <div > Page {page}</div >
}
In Code-Split Components: getRouteApi() import { getRouteApi } from "@tanstack/react-router"
const routeApi = getRouteApi ("/products" )
function ProductFilters ( ) {
const { sort } = routeApi.useSearch ()
return <select value ={sort} > {/* options */}</select >
}
From Any Component: useSearch({ from }) import { useSearch } from "@tanstack/react-router"
function SortIndicator ( ) {
const { sort } = useSearch ({ from : "/products" })
return <span > Sorted by: {sort}</span >
}
Loose Access: useSearch({ strict: false }) function GenericPaginator ( ) {
const search = useSearch ({ strict : false })
return <span > Page: {search.page ?? 1}</span >
}
Writing Search Params
Link with Function Form (Preserves Existing Params) import { Link } from "@tanstack/react-router"
function Pagination ( ) {
return (
<Link
from ="/products"
search ={(prev) => ({ ...prev, page: prev.page + 1 })}
>
Next Page
</Link >
)
}
Link with Object Form (Replaces All Params) <Link to="/products" search={{ page : 1 , filter : "" , sort : "newest" }}>
Reset
</Link >
Programmatic: useNavigate() import { useNavigate } from "@tanstack/react-router"
function SortDropdown ( ) {
const navigate = useNavigate ({ from : "/products" })
return (
<select
onChange ={(e) => {
navigate({
search: (prev) => ({ ...prev, sort: e.target.value, page: 1 }),
})
}}
>
<option value ="newest" > Newest</option >
<option value ="price" > Price</option >
</select >
)
}
Search Param Inheritance Parent route search params are automatically merged into child routes:
import { createFileRoute } from "@tanstack/react-router"
import { z } from "zod"
const shopSearchSchema = z.object ({
currency : z.enum (["USD" , "EUR" ]).default ("USD" ).catch ("USD" ),
})
export const Route = createFileRoute ("/shop" )({
validateSearch : shopSearchSchema,
})
import { createFileRoute } from "@tanstack/react-router"
export const Route = createFileRoute ("/shop/products" )({
component : ShopProducts ,
})
function ShopProducts ( ) {
const { currency } = Route .useSearch ()
return <div > Currency: {currency}</div >
}
Search Middlewares
retainSearchParams — Keep Params Across Navigationimport { createRootRoute, retainSearchParams } from "@tanstack/react-router"
import { z } from "zod"
const rootSearchSchema = z.object ({
debug : z.boolean ().optional (),
})
export const Route = createRootRoute ({
validateSearch : rootSearchSchema,
search : {
middlewares : [retainSearchParams (["debug" ])],
},
})
stripSearchParams — Remove Default Values from URLimport { createFileRoute, stripSearchParams } from "@tanstack/react-router"
import { z } from "zod"
const defaults = { sort : "newest" , page : 1 }
const searchSchema = z.object ({
sort : z.string ().default (defaults.sort ),
page : z.number ().default (defaults.page ),
})
export const Route = createFileRoute ("/items" )({
validateSearch : searchSchema,
search : {
middlewares : [stripSearchParams (defaults)],
},
})
Chaining Middlewares export const Route = createFileRoute ("/search" )({
validateSearch : z.object ({
retainMe : z.string ().optional (),
arrayWithDefaults : z.string ().array ().default (["foo" , "bar" ]),
required : z.string (),
}),
search : {
middlewares : [
retainSearchParams (["retainMe" ]),
stripSearchParams ({ arrayWithDefaults : ["foo" , "bar" ] }),
],
},
})
Custom Serialization Override the default JSON serialization at the router level:
import {
createRouter,
parseSearchWith,
stringifySearchWith,
} from "@tanstack/react-router"
const router = createRouter ({
routeTree,
parseSearch : parseSearchWith (parse),
stringifySearch : stringifySearchWith (stringify),
})
Using Search Params in Loaders via loaderDeps export const Route = createFileRoute ("/products" )({
validateSearch : productSearchSchema,
loaderDeps : ({ search } ) => ({ page : search.page }),
loader : async ({ deps }) => {
return fetchProducts ({ page : deps.page })
},
})
Common Mistakes
1. HIGH: Using zod v3's .catch() with zodValidator() instead of adapter fallback()
const schema = z.object ({ page : z.number ().catch (1 ) })
validateSearch : zodValidator (schema)
import { fallback } from "@tanstack/zod-adapter"
const schema = z.object ({ page : fallback (z.number (), 1 ) })
Important: This only applies when using Zod v3, not when using Zod v4. For v4, using .catch() is correct.
2. HIGH: Returning entire search object from loaderDeps
loaderDeps : ({ search } ) => search
loaderDeps : ({ search } ) => ({ page : search.page })
3. HIGH: Passing Date objects in search params
<Link search={{ startDate : new Date () }}>
<Link search ={{ startDate: new Date ().toISOString () }}>
4. MEDIUM: Parent route missing validateSearch blocks inheritance
export const Route = createRootRoute ({
component : RootComponent ,
})
export const Route = createRootRoute ({
validateSearch : globalSearchSchema,
component : RootComponent ,
})
5. HIGH (cross-skill): Using search as object instead of function loses params
<Link to="." search={{ page : 2 }}>Page 2 </Link >
<Link to ="." search ={(prev) => ({ ...prev, page: 2 })}>Page 2</Link >
References