trying to access **URL Parameter** but getting : cannot destruct params as it is undefined
Answered
futuredevengineer posted this in #help-forum
export async function GET(req:NextRequest, res:NextResponse,{params}:{params:{slug:string}}){
console.log('is it reaching the backend')
try{
console.log(params)
const pullBlog = await BlogModel.findOne({slug:slug})
console.log(pullBlog)
return NextResponse.json({data:pullBlog},{status:200})
}
catch(err){
console.log(err)
return NextResponse.json({data:err},{status:400})
}
}
Answered by Alfonsus Ardani
Refer to this article
https://nextjs.org/docs/app/api-reference/file-conventions/route#parameters
https://nextjs.org/docs/app/api-reference/file-conventions/route#parameters
5 Replies
No, notice the number of parameter
@Alfonsus Ardani No, notice the number of parameter
right, so it is an overloaded function...
it's not an overloaded function either...