Custom folder naming
Unanswered
Transvaal lion posted this in #help-forum
Transvaal lionOP
I want to define the folder names and structures like the image. How and where should I define this?
32 Replies
Northeast Congo Lion
not sure I understand your question, I organized my project like in pic. check here https://nextjs.org/docs/app/building-your-application/routing/route-groups#organize-routes-without-affecting-the-url-path and here https://nextjs.org/docs/app/building-your-application/routing/colocation#split-project-files-by-feature-or-route
@Northeast Congo Lion not sure I understand your question, I organized my project like in pic. check here https://nextjs.org/docs/app/building-your-application/routing/route-groups#organize-routes-without-affecting-the-url-path and here https://nextjs.org/docs/app/building-your-application/routing/colocation#split-project-files-by-feature-or-route
Transvaal lionOP
instead app folder i want everything under src , also instead layout.js i want to use app.js or index.js. so how to make it work?
Northeast Congo Lion
but afaik you still need layout if you want stuff like menus or footer on all pages, otherwise just copy-paste them?
@Northeast Congo Lion then just use src https://nextjs.org/docs/app/building-your-application/configuring/src-directory
Transvaal lionOP
but documentation said to add layout.js into app folder under src folder.
i want to place layout.js into src folder only.. not into src/app folder
layout.js is same thing like core react app.js or index.js without pre-render
As far as I can tell the screenshot you initially provided uses the old
I'm not an expert on this by any means, but as far as I know there is no way to define pages outside of the app folder when using the
pages router, while newer versions of NextJS use the app router. Using the pages router is still supported for backwards compatibility reasons, but generally you should just use the new app based structure.I'm not an expert on this by any means, but as far as I know there is no way to define pages outside of the app folder when using the
app router, like in the screenshotTransvaal lionOP
so all the pages will be under app folder?
can we define those manually?
Actually now that I think about it, I'm pretty sure you can use both simultaneously (again, mostly for migration reasons, generally you should just use the
app router if you can), which it seems they're doing in the screenshot. Unless you're currently migrating a pages project to the app structure I don't see a reason to do this though, as it would just add unnecessary bloat to your route structure@Transvaal lion so all the pages will be under app folder?
As far as I understand it yes, any routes should be defined under your app folder.
@Transvaal lion can we define those manually?
I'm not sure what you mean by this, what is it you want to define?
@robin I'm not sure what you mean by this, what is it you want to define?
Transvaal lionOP
they have inbuilt config where the pages should be placed. i want to define my own config. so i have freedom to change the folder and files name.
module.exports = {
mode: "development",
entry: "./src/index.jsx", // main js
output: {
path: path.resolve(__dirname, "dist"),
publicPath: "/",
}, see in my current react project I can define the entry page like thisentry: "./src/index.jsx", // main jsso in next.js it is layout.js (index.js in react).
they have webpack inbuilt. I think there they placed all the config.
I don't think this is possible. I don't know their internal reasoning for this, but I can only assume it would cause issues due to their insistence on allowing backwards compatibility with the old
More info on these naming conventions here: https://nextjs.org/docs/app/building-your-application/routing#file-conventions
pages router and allowing you to use both simultaneously. The reason you can't change the entry file is that the router uses reserved filenames to easily handle loading states, errors, etc. More info on these naming conventions here: https://nextjs.org/docs/app/building-your-application/routing#file-conventions
The router abstracts React functions like Suspense and Error Boundaries so you can use them through just file conventions
Even though you can't change the
app directory itself, there are also still different ways of structuring your project inside it, so there might still be structuring options available to you that click fit your preference https://nextjs.org/docs/app/building-your-application/routing/colocation@robin Even though you can't change the `app` directory itself, there are also still different ways of structuring your project inside it, so there might still be structuring options available to you that click fit your preference https://nextjs.org/docs/app/building-your-application/routing/colocation
Transvaal lionOP
they said i have freedom to organize project. i place layout.js into src folder and it doesnt work..
This screenshot is using an older version of NextJS where the pages router was still in use. Currently, the app router is standard. This only looks within your app directory.
There is not much difference other than one extra layer of nesting
Transvaal lionOP
here,,
i want layout file like this
I don't think this is currently possible.
However, simply renaming your src folder to app, and then renaming your app folder to something else would already do the trick in this case
but then you'd want to move your assets outside of the folder
Transvaal lionOP
very restrictive . need to see oter SSR instead next.
@robin but then you'd want to move your assets outside of the folder
Transvaal lionOP
Thank you for you time and helps.. ❤️
No worries! Hope you're able to find something that aligns better with your preferences