Next.js Discord

Discord Forum

Dynamic API routes with app router

Unanswered
Masai Lion posted this in #help-forum
Open in Discord
Masai LionOP
Hello! I'm trying to use a dynamic API route (e.g., /api/users/[id]), but it seems like it's not working. request.params and request.query are both undefined.

In the documentation it says:
Dynamic Segments are passed as the params prop to layout, page, route, and generateMetadata functions.

(link: https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes#convention)

But it's not clear what is considered a "prop" with server API route handlers, or how to access that. As mentioned request.params is undefined.


Stackblitz recreation of the issue: https://stackblitz.com/edit/stackblitz-starters-j2qqq8?file=app%2Fapi%2Fusers%2F%5Bid%5D%2Froute.ts

Is anyone here able to provide any guidance?

Tysm in advance 😀

15 Replies

the params object is in second argument
you were reading the doc for the page component not route handler
Masai LionOP
Thank you so much for clarifying that!! @Ray
For what it's worth, the link I shared is indeed under the app router section of the documentation
yes but its for react server component
not route handler
Masai LionOP
Hmm, I guess I would disagree? RSC not mentioned on this page, route handlers are in fact mentioned explicitly 😄
i dont see route handler here
its page.tsx
Masai LionOP
Right here where the red arrow is 🙂 that's the link I shared earlier
yes but for route handler it's in second arg
like the doc said