Reputation: 25
From what I understand from nextjs routes -
blog->[id].jsx gives "blog/1", "blog/2" etc.
But I want to achieve page-subpage-subpage kind of url tree where each page can have subpages & subpages can have further subpages. So url's may look like these -
"page/sub-page/sub-sub-page" etc.
I'm using django treebeard in backend, so pages & subpages urls are all dynamic & comes from API calls. Currently I tried with the below structure -
pages/
index.js
[slug].js
It only gives me ability to fetch only level one pages. I want to acquire multi-level page access.
Anybody ever did it? Please help.
Upvotes: 1
Views: 1144
Reputation: 1001
The URL tree is based on the folders and files in your pages-folder, so you can simply add folders and files to make the tree you need. For example, a blog could have a structure of folders and files like this:
EDIT BASED ON COMMENTS:
I missed that the asker actually meant that they don't know the depth of their tree beforehand. In this case you can use a catch all route like [...id] and the page will get all of the parameters that exist in the query-object.
Upvotes: 1