You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provide an option to make routing independent to folder structure
Non-Goals
No response
Background
Currently, next.js (both app router and pages router) supports file-system based routing. This is a great feature and really convenient.
In other words, Next.js effectively forces the use of a file-system based codebase for implementing routing.
File system and folder structure are important for developers. Files closer to the root directory are often considered more "important", while those deeper in the hierarchy are perceived as less so.
Sometimes there are important pages that are in the nested route. For example, consider a website that editing diary is a main feature. Then next.js forces to make the folder structure like this:
// folder structure
app/
|- page.tsx
|- login/
| `- page.tsx
`- diaryGroups/
`- diaries/
`- edit/
`- page.tsx <- this page is the most important page, but nested because of route!
Developers wishing to contribute must navigate to the deeply nested app/diaryGroups/diaries/edit/page.tsx. In the process, they might encounter similarly named but different files like app/diaryGroups/edit/page.tsx, app/diaryGroups/page.tsx, leading to confusion.
Before file-system based routing, we wrote pages parallel in folder structure, and configured routing in code. Code written below is about how we did it in past years with react-router.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
No response
Background
Currently, next.js (both app router and pages router) supports file-system based routing. This is a great feature and really convenient.
In other words, Next.js effectively forces the use of a file-system based codebase for implementing routing.
File system and folder structure are important for developers. Files closer to the root directory are often considered more "important", while those deeper in the hierarchy are perceived as less so.
Sometimes there are important pages that are in the nested route. For example, consider a website that editing diary is a main feature. Then next.js forces to make the folder structure like this:
Developers wishing to contribute must navigate to the deeply nested
app/diaryGroups/diaries/edit/page.tsx
. In the process, they might encounter similarly named but different files likeapp/diaryGroups/edit/page.tsx
,app/diaryGroups/page.tsx
, leading to confusion.Before file-system based routing, we wrote pages parallel in folder structure, and configured routing in code. Code written below is about how we did it in past years with
react-router
.From then we could leave folder structure support developers' maintenance convenience, and can put
DiaryEditPage
close to the project root directory.If there are some technical issue or should prevent developers' unpredictable usage, supporting it in
next.config.js
will also be very nice.☝️ this is also cool.
Proposal
Beta Was this translation helpful? Give feedback.
All reactions