What are adapters?
Adapters are framework-specific integration layers that enable nuqs to work seamlessly across different React frameworks. They bridge the gap between nuqs’s core URL state management functionality and each framework’s unique routing and navigation systems.Why are adapters needed?
Different React frameworks handle routing and URL updates in fundamentally different ways:- Next.js App Router uses React Server Components and navigation events
- Next.js Pages Router relies on the
next/routermodule - Plain React SPAs work directly with the browser’s History API
- Remix and React Router have their own navigation paradigms
- TanStack Router provides its own state management approach
How adapters work
Every adapter implements theAdapterInterface, which requires two core capabilities:
packages/nuqs/src/adapters/lib/defs.ts:12-18
Available adapters
Next.js App Router
Supported versions: Next.js
>=14.2.0. For older versions, install nuqs@^1.Next.js Pages Router
Plain React (SPA)
For Vite, Create React App, or any React-based SPA:shallow: false will trigger a full page reload instead of just a client-side navigation.
Remix
Supported versions:
@remix-run/react@>=2React Router v6
React Router v7
TanStack Router
Testing adapter
For unit testing components that use nuqs hooks:Creating custom adapters
You can create custom adapters for unsupported frameworks using theunstable_createAdapterProvider function:
Adapter selection
The Next.js adapter automatically detects whether you’re using the app router or pages router at runtime:packages/nuqs/src/adapters/next.ts:6-20