Next.js Discord

Discord Forum

Accessing slug

Answered
Capple posted this in #help-forum
Open in Discord
I have a page at /products/[productId]/page.tsx.

How can I access the slug inside the page component?

I found this in the docs but it's just returning undefined

export default function Page({ params }: { params: { slug: string } }) {
  console.log('slug is:', params.slug)
}
Answered by English Lop
Instead params.slug, use params.productId ?
View full answer

7 Replies

Bump
Share your files structure
English Lop
Instead params.slug, use params.productId ?
Answer
Instead of slug it should be whatever you put instead the block brackets "[ ]"
Thank you everyone! The productId worked. I feel dumb as hell now that I didn't think of it myself, i was under the assumption it had to be named slug for some reason.