TanStack Router support is experimental and does not yet cover TanStack Start (the SSR framework).
Installation
1
Install nuqs
Install nuqs in your TanStack Router project:
2
Add the adapter to your root route
Wrap your app with
NuqsAdapter in your root route component:src/routes/__root.tsx
The
NuqsAdapter should wrap the <Outlet /> component to provide context to all routes.3
Use nuqs hooks in your route components
Now you can use
useQueryState and useQueryStates in any route component:src/routes/search.tsx
Version Requirements
- @tanstack/react-router:
^1 - React:
>=18.2.0or^19.0.0-0
Features
Integration with TanStack Router
The adapter uses TanStack Router’s nativeuseLocation() and useRouter() hooks, ensuring seamless integration with TanStack Router’s navigation system.
Automatic Type Handling
TanStack Router JSON-parses objects in search params by default. The nuqs adapter automatically handles this:Navigation Options
The adapter respects nuqs history and scroll options:replace and resetScroll options.
Optimized Performance
The adapter has arateLimitFactor of 1, meaning it’s optimized for TanStack Router’s navigation performance characteristics.
How It Works
The TanStack Router adapter:- Uses
useLocation()to read search params from the route state - Filters and watches only the keys used by nuqs hooks
- Converts TanStack Router’s search object format to
URLSearchParams - Uses
navigate()to update the URL with custom encoding - Wraps navigation in
startTransitionfor scroll restoration support - Handles TanStack Router’s object serialization automatically
Examples
Search with Results
src/routes/search.tsx
Filters with Multiple States
src/routes/products.tsx
Pagination with History
src/routes/blog.tsx
Working with TanStack Router Search Params
Mixing nuqs with TanStack Router’s Search Params
You can use nuqs alongside TanStack Router’s built-in search param validation:src/routes/products.tsx
Limitations
TanStack Start (SSR) Not Supported
The current adapter is designed for client-side TanStack Router applications. Support for TanStack Start (the SSR framework) is not yet available.JSON Object Handling
TanStack Router automatically JSON-parses objects in search params. When usingparseAsJson, the adapter re-stringifies these objects to ensure compatibility. This adds a small overhead but maintains consistency with other nuqs adapters.
Troubleshooting
Search params not updating
Ensure:- The
NuqsAdapteris placed in your root route and wraps<Outlet /> - Your route components are properly nested under the root route
- You’re using TanStack Router v1 or later