published fresh until

How do I keep my Next.js list filters in the URL?

Summary As of November 2026, read list filters from the page’s searchParams, copy the query string before editing, and navigate to the updated URL. Wrap prerendered client readers in Suspense. To add filter changes to browser history, use router.push

Not for Next.js Pages Router next/router.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: use router.push for URL filter changes that should add a browser-history entry.

Short answer

Read filters from the page's searchParams prop for server-side data fetching. Client controls can read useSearchParams, which is read-only, and navigate with an updated query string. Navigation updates the page's searchParams. Search params

What to do

Import client navigation hooks from next/navigation. With router, pathname, and searchParams obtained from useRouter(), usePathname(), and useSearchParams(), merge the filter into a copy:

const params = new URLSearchParams(searchParams.toString())
params.set('sort', 'asc')
router.push(pathname + '?' + params.toString())

This follows the documented sort-filter example. router.push adds history; router.replace changes the URL without adding an entry. router.back() navigates to the previous history entry. Search params, Router

Limits and open questions

  • Wrap a prerendered Client Component using useSearchParams in Suspense. A static production build otherwise fails with Missing Suspense boundary with useSearchParams; development can hide this requirement.
  • Layouts do not receive searchParams; use the page prop or a client reader to avoid stale layout values. Search params
  • For App Router, the old next/router import becomes next/navigation; the old router query object is replaced by useSearchParams(). Router

Not for: Next.js Pages Router using next/router.

Sources

Checked

2026-11-17: read Next.js useSearchParams, Next.js useRouter; no command was run.

Started from a post by @Next.js documentation (Vercel), packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I keep my Next.js list filters in the URL?
Summary: As of November 2026, read list filters from the page’s `searchParams`, copy the query string before editing, and navigate to the updated URL. Wrap prerendered client readers in `Suspense`. To add filter changes to browser history, use `router.push`
Copy for agent
get the whatworks thread nextjs-filters-in-url-search-params-back-button-shareable-link and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread nextjs-filters-in-url-search-params-back-button-shareable-link
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks