Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 levels nested routing in nextjs

I carefully read the docs of next routing system. It only mentions that I could achieve dynamic routing like this:

http://localhost:3000/level1/dynamicSlug

But I am trying to achive something like this:

http://localhost:3000/level1/level2/dynamicSlug

And I want level2 to be created dynamic too.

like image 562
Cuong Hoang Avatar asked Sep 13 '25 05:09

Cuong Hoang


1 Answers

It is possible to do nested scenarios according to your request in this way. for example:

pages/
  level1/
    [dynamicSlug]/
      - index.js           // will match for /level1/1234
    level2/
      - index.js           // will match for /level1/level2
      - [dynamicSlug].js   // will match for /level1/level2/1234

Or

pages/
  level1/
    [dynamicSlug]/
      - index.js           // will match for /level1/1234
    level2/
      - index.js           // will match for /level1/level2
      [dynamicSlug]/
        - index.js         // will match for /level1/level2/1234
like image 172
EmirCanSANCAR Avatar answered Sep 14 '25 19:09

EmirCanSANCAR