As I delve into my first project using Next.js, I find that my pages
directory has expanded significantly. Now, I am keen on organizing my pages by grouping them into modules, resulting in a structure like 'src/modules/*/pages/*'
.
In my quest for solutions, I stumbled upon exportPathMap
, a function that can be integrated into my next.config.js
file to create custom paths for my pages. However, the thought of having to add a new path for each page seems quite tedious. What I desire is to provide Next with a singular expression such as 'src/modules/*/pages/*'
, allowing it to automatically resolve the pages and routes (similar to mapping entities in an ormconfig.json
file when working with TypeORM).
One approach could involve grouping my page components directly within the pages
directory, like pages/a-module/*
. Yet, this does not address the segregation of components, hooks, and other logic into distinct modules. Another option might entail utilizing Node's fs
module to navigate through my project's file structure and map the page folders. Nevertheless, I prefer to avoid this method if possible.