Next.js Discord

Discord Forum

How to get dynamic params like "?filter=test" on the page.tsx ?

Answered
Long-legged ant posted this in #help-forum
Open in Discord
Avatar
Long-legged antOP
Hello, so i need dynamic params on the page.tsx, and after call a request, it's must start with "?" and not "/" how deal with that ? I don't know how to do that because next js create static page. Thank you.
Answered by Nile Crocodile
They are passed through props:
export default function Page({
  params,
  searchParams,
}: {
  params: { slug: string };
  searchParams?: { [key: string]: string | string[] | undefined };
}) {
  return <h1>{searchParams?.greeting || "Hello!"}</h1>;
}

docs: https://nextjs.org/docs/app/api-reference/file-conventions/page
View full answer

4 Replies

Avatar
Long-legged antOP
More generally, it's possibile to do query string on page.tsx on server side ?
Avatar
Nile Crocodile
They are passed through props:
export default function Page({
  params,
  searchParams,
}: {
  params: { slug: string };
  searchParams?: { [key: string]: string | string[] | undefined };
}) {
  return <h1>{searchParams?.greeting || "Hello!"}</h1>;
}

docs: https://nextjs.org/docs/app/api-reference/file-conventions/page
Answer
Avatar
Long-legged antOP
Thx. Can we use it on static page ?
Avatar
@Long-legged ant Thx. Can we use it on static page ?
Avatar
yes. but you need to use client component