Version Selection
React Router v6
For applications usingreact-router-dom@^6:
React Router v7
For applications usingreact-router@^7:
Installation
1
Install nuqs
Install nuqs in your React Router project:
2
Set up the adapter for your version
Choose the setup instructions for your React Router version:
- React Router v6
- React Router v7
Wrap your
RouterProvider with the NuqsAdapter:src/main.tsx
3
Use nuqs hooks in your routes
Now you can use
useQueryState and useQueryStates in any route component:src/routes/search.tsx
Version Requirements
React Router v6
- react-router-dom:
^6 - React:
>=18.2.0or^19.0.0-0
React Router v7
- react-router:
^7 - React:
>=18.2.0or^19.0.0-0
Features
Integration with React Router Navigation
Both adapters use React Router’s nativeuseNavigate() and useSearchParams() hooks, ensuring perfect integration with React Router’s navigation system.
Optimistic UI Updates
UseuseOptimisticSearchParams for optimistic UI updates during navigation:
Shallow Updates
By default, URL updates are shallow (client-side only):shallow: false:
Dynamic Routes
The adapter works seamlessly with dynamic route segments:src/routes/post.$id.tsx
How It Works
Both React Router adapters:- Use React Router’s
useSearchParams()to read current search params - Use React Router’s
useNavigate()to update the URL - Automatically handle route transitions and history changes
- Provide optimistic updates through
useOptimisticSearchParams() - Filter and sync only the relevant search params for each component
Examples
Tabbed Interface
Product Filters with Multiple States
Pagination with History
Troubleshooting
Wrong adapter version
Make sure you’re using the correct adapter for your React Router version:Search params not updating
Ensure:- The
NuqsAdapterwraps your router or app - Components using nuqs hooks are inside the router context
- You’re not preventing default on navigation events
Deprecation warning
If you see a deprecation warning aboutnuqs/adapters/react-router, update your import to specify the version: