Frecoder
Frecoder

Reputation: 33

Dynamic route in Next.js

Before describing my question I would like to show you my file structure.

app|
   |->api|
         |->user|
                |->[userId].js

[userId].js:

export  function GET(req){
   return new Response("Hii")}

This is my file structure for the backend. When I put a get request to

localhost:3000/api/user/12

I'm not getting any response from the server. It is giving 404 error. May I know where the problem is.

Thanks in advance.

Upvotes: 0

Views: 75

Answers (1)

zzev
zzev

Reputation: 1

The app folder works slightly different. Route Handlers are now defined in a route.js file inside the app directory. So, instead of your folder structure, try this one:

app|
   |->api|
         |->user|
                |->[userId]|
                           |route.js

Upvotes: 0

Related Questions