Next.js Discord

Discord Forum

Can I use URL Query Parameters (searchParams) in a page.tsx file?

Answered
Broken Nokia posted this in #help-forum
Open in Discord
I want to have URL parameters that affects a small part of the page content on the root page of my application. Is there a way i can do this?
For additional context: I had a selector box on the root page who's default value i would like to set based on URL parameters
How can I do this?
Answered by B33fb0n3
yes you can do that. Your page.tsx receive also the [searchParams as prop](https://nextjs.org/docs/app/api-reference/file-conventions/page#searchparams-optional). This prop can now be accessed and contains your searchParams like this:
/shop?a=1&b=2    =>    { a: '1', b: '2' }
View full answer

3 Replies

Answer
Thank you 😊