Next.js Discord

Discord Forum

not able to get query string parameters from the url

Answered
bscdev#1145 posted this in #help-forum
Open in Discord
I have a nextjs 13.4.2 application where i want to pass page query yo api/route.js.
My api query is 'api/post?page=1'

Now i want to get this page query in api/post/route.js . which is a issue

export default GET = async(request)=>{
console.log(request)

}

when console the request i found the page query on url object in searchParams
so I destructure the search params but can not get the page query as a value.

Please help
Answered by joulev
const { searchParams } = request.nextUrl;
const page = searchParams.get("page");
View full answer

2 Replies