How to get dynamic params like "?filter=test" on the page.tsx ?
Answered
Long-legged ant posted this in #help-forum
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:
docs: https://nextjs.org/docs/app/api-reference/file-conventions/page
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
4 Replies
Long-legged antOP
More generally, it's possibile to do query string on page.tsx on server side ?
Nile Crocodile
They are passed through props:
docs: https://nextjs.org/docs/app/api-reference/file-conventions/page
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
Long-legged antOP
Thx. Can we use it on static page ?
@Long-legged ant Thx. Can we use it on static page ?
yes. but you need to use client component