Next.js: Ability to rename 'pages' directory

Created on 26 Sep 2018  路  3Comments  路  Source: vercel/next.js

Feature request

I would love the ability to rename the pages directory, for my case I would like to call it "routes." This would then allow me to use the "route" components (currently pages) as basic wrappers that would essentially just reference a different component. The reason I want this is since Next currently has no intention of supporting the glob pattern under pages I would like to be able to write unit tests and css for my wrapper components.

  • routes/
    -- about.jsx

  • pages/
    -- about/
    ---- about.jsx
    ---- about.spec.jsx
    ---- about.scss

The above structure is what I'm hoping to achieve, of course I could just name "pages" something different like "containers" but I feel as if that could be confusing to future developers on this project. Being able to rename "pages" to "routes" would then free up the name "pages" to use instead of "containers" (frequently used to describe class based components).

Is this something that is possible in Next today? Maybe something that could be implemented?

Thanks for any help!

Most helpful comment

The interesting part of this is that you could already achieve this without renaming or changing anything in Next.js, by just inverting the structure you want:

pages as the routes, and routes as the implementation.

We're not planning to make pages a configuration option as said in the other issue. There are a few reasons for this but the main reason is that it's an established convention and anyone opening your project that is familiar with Next.js will be able to know everything that is put into pages is immediately public. By changing this, for example to routes, you're potentially introducing confusion.

All 3 comments

Note, this is a separate question from the one that is posted over and over about changing the path of pages to be under src or something of the sort, this is specifically about renaming the directory in config.

The interesting part of this is that you could already achieve this without renaming or changing anything in Next.js, by just inverting the structure you want:

pages as the routes, and routes as the implementation.

We're not planning to make pages a configuration option as said in the other issue. There are a few reasons for this but the main reason is that it's an established convention and anyone opening your project that is familiar with Next.js will be able to know everything that is put into pages is immediately public. By changing this, for example to routes, you're potentially introducing confusion.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

havefive picture havefive  路  3Comments

swrdfish picture swrdfish  路  3Comments

sospedra picture sospedra  路  3Comments

flybayer picture flybayer  路  3Comments

olifante picture olifante  路  3Comments