How do you get URL query parameters in the Next.js App Router?

← Next.js answers

In a page, read the searchParams prop; in a Client Component, use the useSearchParams hook. Dynamic path segments come from params.

// app/products/[id]/page.tsx  ->  /products/42?sort=price
export default async function Page({
  params,
  searchParams,
}: {
  params: Promise<{ id: string }>;
  searchParams: Promise<{ sort?: string }>;
}) {
  const { id } = await params;
  const { sort } = await searchParams;
  return <p>Product {id}, sorted by {sort ?? "default"}</p>;
}
"use client";
import { useSearchParams } from "next/navigation";
 
export function SortLabel() {
  const sort = useSearchParams().get("sort");
  return <span>{sort}</span>;
}

Using searchParams makes a page dynamic, because the value is only known per request. On older Next.js versions, params and searchParams are plain objects rather than promises.

Related questions

Start debugging smarter today

Try Bugsee for free — no commitments, no hidden fees.

Free sign upLive demoNo credit card required