An in real life
An in real life

Reputation: 108

How can I access to [id]/routeName in Next.js

I have simple project that when user go to the link like: localhost:3000/course/[id] Then user click join and the url will change to localhost:3000/course/[id]/routeName How can i create folder like that in pages ? Thank you very much!

Upvotes: 1

Views: 917

Answers (2)

serraosays
serraosays

Reputation: 7889

You want what Next calls 'Multiple dynamic route segments'. Inside of your /pages directory:

  • you want a folder called course
  • inside of that you'd have another folder called [id]
  • inside of that folder, you'd want a file called [routeName].js

The path would look like:

/pages/course/[id]/[routeName].js

Upvotes: 1

An in real life
An in real life

Reputation: 108

I figured it out ! If you have the same problem like me !

pages
   |-categories
       |-[category_slug]
           |-index.js     
           |-product
               |-[product_slug].js  

That's it!

Upvotes: 0

Related Questions