Reputation: 3508
I've been reading through the documentation, which is great, however I'm still not entirely sure the best way of creating a nested route in NextJS.
In my example I have modules that have nested lessons. Or in other words, my module could be a book and each lesson a chapter.
So, my current thought is to have my pages directory like so:
pages/modules/[mid]/lessons/[lid]
Pretty generic route path, but it feels off to create a dir path like this:
/Pages
--/modules
----[id].js
----/lessons
------[id].js
It seems very very coupled to modules. What happens if I want a different route to lead to lessons or if I make another page that just GETs all lessons regardless of modules. What then?
Would the ex below be a normal/suitable design? Seems a bit messy having all these tucked away places to have lessons appear. I'm sure I'll get a better grip of it soon enough. Just want to make sure I'm not going well off the beaten path.
/Pages
--/modules
----[id].js
----/lessons
------[id].js
--/lessons
----index.js
Thanks!
Upvotes: 0
Views: 104
Reputation: 560
If you want to nest the entire content of a directory under a route parameter you can name the directory itself between brackets. Then all the content under moduleId directory will receive a module Id.
You can have
/Pages
--[moduleId]
----/lessons
------[id].js
Upvotes: 1