The Next.js App Router adapter enables nuqs to work seamlessly with Next.js 14.2.0 and above using the App Router.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/47ng/nuqs/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Add the adapter to your root layout
Wrap your application with the
NuqsAdapter in your root layout file:app/layout.tsx
The adapter must be placed inside the
<body> tag and wrap all content that uses nuqs hooks.Version Requirements
- Next.js:
>=14.2.0 - React:
>=18.2.0or^19.0.0-0
Features
Shallow Updates (Default)
By default, URL updates are client-side only and don’t trigger server re-renders:Server Re-renders
Opt into server-side rendering updates by settingshallow: false:
Transitions
Combine with React’suseTransition for loading states during server updates:
How It Works
The Next.js App Router adapter:- Uses
useSearchParams()fromnext/navigationto read the current URL state - Uses
useOptimistic()to provide instant UI updates - Calls
router.replace()for non-shallow updates to trigger server re-renders - Patches the History API to detect navigation events and reset internal queues
- Batches multiple state updates efficiently
Server Components
For accessing search params in Server Components, usecreateSearchParamsCache:
app/page.tsx
Troubleshooting
Adapter must be inside <body>
The adapter relies on browser APIs and must be rendered inside the <body> tag. Placing it in <head> or outside <html> will cause errors.
Not working with Next.js 14.1 or older
The App 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
Search params not updating
Make sure:- The component using nuqs hooks has the
'use client'directive - The component is a child of the
NuqsAdapter - You’re not accidentally using the wrong adapter (e.g., pages router adapter)