Hi all,
I was going through the docs and was a bit confused about how are we handling the nested routes in redwood js… is it like
- generate page
then - move them to to respective directories
- run generate type command
Is there any better way to do it?
Hi all,
I was going through the docs and was a bit confused about how are we handling the nested routes in redwood js… is it like
Is there any better way to do it?
There is not really a thing in redwood js as nested routes. We keep the routes file flat on purpose.
Thanks for taking the time to reply. Now that I think of it, it was a stupid question. That’s how we learn! Thanks again!
Hi! I don’t think it’s a stupid question at all. Nested routes are a powerful feature in Next.js, as they provide better organization, especially when dealing with many nested pages/routes.
I create them just like in React:
Step 1 :
Create your root page with:
yarn redwood generate page account /account
Step 2 :
Create your nest page with
yarn rw g page edit /account/edit
Step 3 :
Manually move the nested EditPage folder in the root AccountPage.
At this point, the Routes.tsx will not find your EditPage(nested in AccountPage).
Step 4 :
Import your EditPage in the Routes.tsx
import EditPage from ‘src/pages/AccountPage/EditPage/EditPage’
Results
I don’t know if there is a better way of doing it or if it has a negative effect on performance. I think it’s also possible with components, but personally, I don’t use them for this purpose.
If there is a better way to implement nested routes/pages, please let me know.