Skip to main content
The Next.js Pages Router adapter enables nuqs to work with Next.js 14.2.0 and above using the Pages Router (the traditional pages/ directory structure).

Installation

1

Install nuqs

First, install nuqs in your Next.js project:
2

Add the adapter to _app.tsx

Wrap your application with the NuqsAdapter in your custom App component:
pages/_app.tsx
If you don’t have a custom _app.tsx, create one following the Next.js documentation.
3

Use nuqs hooks in your pages

Now you can use useQueryState and useQueryStates in any page component:
pages/search.tsx

Version Requirements

  • Next.js: >=14.2.0
  • React: >=18.2.0 or ^19.0.0-0
For Next.js versions older than 14.2.0, use nuqs v1.x instead, which doesn’t require the adapter setup.

Features

Shallow Updates (Default)

By default, URL updates don’t trigger getServerSideProps to re-run:

Server-Side Updates

Opt into re-running getServerSideProps by setting shallow: false:

Dynamic Routes

The adapter automatically handles dynamic route segments, preserving them during URL updates:
pages/post/[id].tsx
The adapter correctly separates dynamic route parameters (id) from search params (page).

How It Works

The Pages Router adapter:
  1. Uses useRouter() from next/compat/router to access the router
  2. Reads search params from router.query
  3. Updates the URL using router.push() or router.replace()
  4. Automatically extracts and preserves dynamic route segments
  5. Listens to routeChangeStart and beforeHistoryChange events to reset queues

Server-Side Rendering

You can access and parse search params in getServerSideProps:
pages/products.tsx

Catch-All Routes

The adapter supports catch-all and optional catch-all routes:
pages/docs/[...slug].tsx

Troubleshooting

Search params conflict with dynamic route segments

If you have a search param with the same name as a dynamic segment, the dynamic segment takes precedence:
Avoid naming conflicts by using different names for route segments and search params.

getServerSideProps not re-running

Make sure you’re passing shallow: false when updating state:

Not working with Next.js 14.1 or older

The Pages Router adapter requires Next.js 14.2.0 or newer. For older versions:
  • Upgrade to Next.js 14.2.0+, or
  • Use nuqs v1.x which has built-in support for older Next.js versions