Next.js Discord

Discord Forum

How to access query parameters(app router) version nextjs 14.2

Answered
Barbary Lion posted this in #help-forum
Open in Discord
Avatar
Barbary LionOP
This is my parent code
<Link
key={index}
prefetch={true}
href={{
pathname: /project/client-projects/${clientProject.project_id},
query: {
projectId: clientProject.project_id,
workId: clientProject.work_id
}
}}
I want to access the projectid and workId on child page which is on server side
how can I access this both query ?

9 Replies

Answer
Avatar
Barbary LionOP
is searchParams is server side ?
Avatar
Asian black bear
Yes.
Avatar
Barbary LionOP
let me try
Avatar
Barbary LionOP
on docs params were there I used that and i am getting undefined
Image
Avatar
Asian black bear
Because you need to use searchParams and not params
Avatar
Barbary LionOP
not able to understand this code
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
Avatar
Asian black bear
You just replace the name of params in your screenshot with searchParams
Avatar
Barbary LionOP
thank you