How to access query parameters(app router) version nextjs 14.2
Answered
Barbary Lion posted this in #help-forum
Barbary LionOP
This is my parent code
<Link
key={index}
prefetch={true}
href={{
pathname:
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 ?
<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
Asian black bear
Answer
Barbary LionOP
is searchParams is server side ?
Asian black bear
Yes.
Barbary LionOP
let me try
Barbary LionOP
on docs params were there I used that and i am getting undefined
Asian black bear
Because you need to use
searchParams
and not params
Barbary LionOP
not able to understand this code
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
Asian black bear
You just replace the name of
params
in your screenshot with searchParams
Barbary LionOP
thank you