Skip to main content
The React Router adapter enables nuqs to work with React Router applications. There are separate adapters for React Router v6 and v7.

Version Selection

React Router v6

For applications using react-router-dom@^6:

React Router v7

For applications using react-router@^7:
The generic import nuqs/adapters/react-router is deprecated and will be removed in nuqs v3.0.0. Always specify the version explicitly.

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:
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.0 or ^19.0.0-0

React Router v7

  • react-router: ^7
  • React: >=18.2.0 or ^19.0.0-0

Features

Integration with React Router Navigation

Both adapters use React Router’s native useNavigate() and useSearchParams() hooks, ensuring perfect integration with React Router’s navigation system.

Optimistic UI Updates

Use useOptimisticSearchParams for optimistic UI updates during navigation:
This returns the search params that will be applied after pending transitions complete.

Shallow Updates

By default, URL updates are shallow (client-side only):
To trigger full page navigation, use shallow: false:

Dynamic Routes

The adapter works seamlessly with dynamic route segments:
src/routes/post.$id.tsx

How It Works

Both React Router adapters:
  1. Use React Router’s useSearchParams() to read current search params
  2. Use React Router’s useNavigate() to update the URL
  3. Automatically handle route transitions and history changes
  4. Provide optimistic updates through useOptimisticSearchParams()
  5. 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:
  1. The NuqsAdapter wraps your router or app
  2. Components using nuqs hooks are inside the router context
  3. You’re not preventing default on navigation events

Deprecation warning

If you see a deprecation warning about nuqs/adapters/react-router, update your import to specify the version: