Next.js Discord

Discord Forum

dynamic api routes with app directory

Answered
Drever posted this in #help-forum
Open in Discord
DreverOP
It seems that api routes have now changed to only take in 1 Request paramater, what is the best practice for getting the id param out of urls like /user/[id]/posts?

13 Replies

Answer
@Giant panda https://nextjs.org/docs/app/api-reference/file-conventions/route#context-optional
DreverOP
is there a built in type for the context
@Giant panda https://nextjs.org/docs/app/api-reference/file-conventions/route#context-optional
DreverOP
and how do I get server session in nextauth, now there is no req, res params
ah nvm
yeah
just use authOptions
the context can vary and is determined by the folder structure hence itsa not yet automatically detected by Typescript
yet it works still
yeah its very flexible
DreverOP
do I even need req?
hmm, i dont think so