Next.js Discord

Discord Forum

trying to access **URL Parameter** but getting : cannot destruct params as it is undefined

Answered
futuredevengineer posted this in #help-forum
Open in Discord
Avatar
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})
    }


}

5 Replies