How can I access query in api routes in app directory of next js.As I want to do pagination by querying my requested url

225 Views Asked by At

enter image description here

I am getting squiggly lines below query saying Property 'query' does not exist on type 'Request'.

enter image description here This is my blog component

Along with answer, Could someone provide an example of their work where they have accomplished a similar task?

1

There are 1 best solutions below

0
On
export async function POST(req: Request) {
  const {searchParams}=new URL(req.url)

}

its type is

const searchParams: URLSearchParams

it has get method.

 get(name: string): string | null;

let's say you have "location" query param

const location=searchParams.get("location")