---
title: "How do you get URL query parameters in the Next.js App Router?"
description: "Read query strings with the searchParams prop in a page, or useSearchParams in a client component. Dynamic segments come from the params prop."
url: "https://bugsee.com/answers/nextjs/get-url-query-params/"
---

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

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

```tsx
// 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>;
}
```

```tsx
"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

- [How do you set a cookie on the server in Next.js?](https://bugsee.com/answers/nextjs/set-a-cookie-on-the-server/)
