Next.js Discord

Discord Forum

Is there any issue if i use this as a api of `/api/user/[userId]`

Answered
Αμμάν Ριζουάν posted this in #help-forum
Open in Discord
Avatar
Image
Answered by B33fb0n3
I guess I already linked you the correct link. Take a look at it here: https://nextjs.org/docs/app/building-your-application/routing/route-handlers#dynamic-route-segments

You might be interested in directly viewing at the code:
// route: app/items/[slug]/route.ts

export async function GET(
  request: Request,
  { params }: { params: Promise<{ slug: string }> }
) {
  const slug = (await params).slug // 'a', 'b', or 'c'
}
View full answer

10 Replies

Avatar
@Αμμάν Ριζουάν Click to see attachment
Avatar
No. Your way of getting the dynamic param is a bit weird, but the rest is fine
I have seen this in YT tutorial if you have a better way then please share
Avatar
@Αμμάν Ριζουάν So how can i get a param ??
Avatar
I guess I already linked you the correct link. Take a look at it here: https://nextjs.org/docs/app/building-your-application/routing/route-handlers#dynamic-route-segments

You might be interested in directly viewing at the code:
// route: app/items/[slug]/route.ts

export async function GET(
  request: Request,
  { params }: { params: Promise<{ slug: string }> }
) {
  const slug = (await params).slug // 'a', 'b', or 'c'
}
Answer
Avatar
It is not working for api route
Avatar
@Αμμάν Ριζουάν It is not working for api route
Avatar
you need to exchange your stuff here to the code I already wrote. Also make sure to change the slug to your userId, as the folder path is different
Image
Avatar
Ok let me check again
Avatar
Hmm it working
Thanks
Avatar
happy to help