Next.js Discord

Discord Forum

get path param on server function

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
So i wanna go to /category/id and query the category on the server function, but useParams works only on client side, I wonder how can I get that id on the server function. forive me if this ound basic but the DX in nextjs is really hard.

7 Replies

export default async function Page({
  params,
}: {
  params: Promise<{ slug: string }>
}) {
  const slug = (await params).slug
  return <div>My Post: {slug}</div>
}
so u have app/category/[id]/page.tsx
and replace slug by id
@gin https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes
West African LionOP
thanks, I almost gave up on nextjs
@West African Lion thanks, I almost gave up on nextjs
can u mark this as solved?
:)