#Is there a downside to not excluding folders from the route if it's not meant to be a route

1 messages · Page 1 of 1 (latest)

bitter briarBOT
#

Hi @grizzled jungle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, there can be potential downsides to not excluding folders from the route if they're not meant to be a route. In Next.js, each folder in a route represents a route segment and is mapped to a corresponding segment in a URL path. This means that if a folder is not meant to be a route but is not excluded, it could potentially become part of the URL path, which might not be the desired behavior.

One way to exclude a folder from the route in Next.js is by using Route Groups. Route groups can be created by wrapping a folder's name in parenthesis: (folderName). This indicates the folder is for organizational purposes and should not be included in the route's URL path. This allows you to organize your route segments and project files into logical groups without affecting the URL path structure.

Another way is by using Private Folders. Private folders can be created by prefixing a folder with an underscore: _folderName. This indicates the folder is a private implementation detail and should not be considered by the routing system, thereby opting the folder and all its subfolders out of routing.

Not excluding folders that are not meant to be routes could lead to confusion and potential naming conflicts. It could also result in a more polluted route path for users. Therefore, it's recommended to properly organize your project files and route segments using the features provided by Next.js.

#

@grizzled jungle kapa.ai is still learning and improving, please let us know how it did by reacting below

grizzled jungle
#

@bitter briar right now I have a route folder, inside it I have the page.tsx file, components folder, vm folder, adapter folder. However, all these folders get confusing because if I need a nested route, it'd be another folder, I'd like to create one folder for the components, vm, and adapter. However, I'm having trouble thinking of a name for it. Got suggestions?

bitter briarBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Sure, naming conventions can be a bit tricky, especially when you want to keep your project structure clean and understandable. Here are a few suggestions:

  1. lib: This is a common name used for a directory that holds "library" code, or code that is used across your application. This could be a good place to put your components, view models (vm), and adapters.

  2. shared: This name indicates that the code inside this directory is shared across multiple parts of your application.

  3. core: This name is often used to indicate fundamental code that the rest of the application depends on.

  4. utils or helpers: These names are often used for directories that contain utility functions or helper code.

Remember, the most important thing is that the name makes sense to you and your team. It should give a clear indication of what kind of files are inside the directory.

Also, keep in mind that Next.js allows you to organize your files and folders in a way that works best for you and your team. There's no "right" or "wrong" way when it comes to organizing your own files and folders in a Next.js project. The key is to choose a strategy that works for you and your team and be consistent across the project.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@grizzled jungle kapa.ai is still learning and improving, please let us know how it did by reacting below

grizzled jungle
#

@bitter briar these folders are meant to be for that specific page only, not the entire application

bitter briarBOT
#

Let me check the knowledge base for you. One moment! :books:

#

In that case, you might want to consider a name that indicates the folder contains resources specific to that page. Here are a few suggestions:

  1. local: This name indicates that the components, view models (vm), and adapters in this folder are local to the specific page.

  2. pageResources: This name clearly states that the folder contains resources for the specific page.

  3. pageAssets: Similar to pageResources, this name indicates the folder contains assets for the specific page.

  4. pageComponents: This name indicates that the folder contains components specific to the page.

Remember, the name should be meaningful and self-explanatory to you and your team. It's also a good practice to add a README file in each folder explaining what it contains and how the files inside should be used.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@grizzled jungle kapa.ai is still learning and improving, please let us know how it did by reacting below

grizzled jungle
#

@bitter briar I take that back. It is meant to be for that route

bitter briarBOT
#

Let me check the knowledge base for you. One moment! :books:

#

If the folders are meant to be specific to that route, you might want to consider a name that indicates the folder contains resources specific to that route. Here are a few suggestions:

  1. routeResources: This name clearly states that the folder contains resources for the specific route.

  2. routeAssets: Similar to routeResources, this name indicates the folder contains assets for the specific route.

  3. routeComponents: This name indicates that the folder contains components specific to the route.

  4. routeSpecific: This name indicates that the contents of the folder are specific to the route.

Remember, the name should be meaningful and self-explanatory to you and your team. It's also a good practice to add a README file in each folder explaining what it contains and how the files inside should be used.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: