Route groups and private folders
Parenthesized folders organize routes and layouts without changing URLs; underscore folders opt out of routing. Caveats: root layouts and path clashes.
Route groups and private folders
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Wrapping a folder name in parentheses, such as `(marketing)`, makes a route group: it organizes files and can carry its own layout, but is left out of the URL.
- A route group lets a subset of routes share a layout, or lets different sections have different root layouts, without any change to their paths.
- Prefixing a folder with an underscore, such as `_components`, makes it a private folder that the router ignores completely.
- Two caveats apply: routes in different groups must not resolve to the same URL, and moving between different root layouts triggers a full page load.
Two separate problems, two small conventions
As a project grows, two things go wrong in the app folder. The first is organization: you have marketing pages, shop pages and an admin area, and you want them grouped, but adding a folder adds a URL segment and you want the URLs flat. The second is clutter: components and helpers beside your pages make the tree hard to scan. Next.js gives you one convention for each.
Route groups: folders the URL ignores
Wrap a folder name in parentheses and it disappears from the path:
app/
(marketing)/
page.tsx → /
about/page.tsx → /about
(shop)/
cart/page.tsx → /cart
account/page.tsx → /account
Nothing about the URLs changed, but the tree now reads as two sections. A route group is purely a folder name; there is no special file to add.
Layouts for a subset of routes
The more useful thing a group does is carry a layout. Put layout.tsx inside (shop) and only the shop routes get it:
// app/(shop)/layout.tsx
export default function ShopLayout({ children }: { children: React.ReactNode }) {
return (
<div>
<nav>Cart | Account</nav>
{children}
</div>
);
}
/cart and /account render inside it; /about does not. This is how you opt specific routes into a layout while leaving siblings out, without nesting them under a shared URL prefix. It also lets you scope a loading.tsx to a subset: put the page in a group such as (overview) and move loading.tsx into it, so the loading UI applies to that page but not to its sibling routes.
You can go further and give each group its own root layout, each with its own <html> and <body>, by removing the top-level app/layout.tsx. Then the home page must live inside one of the groups, for example app/(marketing)/page.tsx.
Private folders: ignored by routing
Prefix a folder with an underscore and the router skips it and everything inside:
app/dashboard/
page.tsx
_components/
chart.tsx
stat-card.tsx
Strictly, you do not need this. A folder without a page or route file is not a route anyway, as covered in the project structure. Private folders earn their place in four ways: they separate UI code from routing code at a glance, give a consistent convention across the project, sort together in an editor, and avoid collisions with special file names Next.js might reserve in future. If you ever need a real URL segment that starts with an underscore, write %5F in the folder name.
Caveats
Next.js documents three:
- Different root layouts mean a full page load. If two groups each have their own root layout, a link between them reloads the document instead of doing a client-side transition. This applies only to multiple root layouts, not to ordinary group layouts.
- Paths must not clash. Two groups that both contain
about/page.tsxresolve to the same/about, and that is an error. - Top-level root layout. With multiple root layouts and no
app/layout.tsx, make sure the home route sits inside a group.
What the video covers
Codevolution’s route groups video (chapters: introduction, implementing authentication routes, organizing routes for developer experience, creating and using route groups) uses a login/register/forgot-password example to show routes grouped without changing paths. The private folders video, linked under deeper, is a separate short clip in the same series. Both were recorded for Next.js 15; the conventions are unchanged in 16.
Where this fits
You now have the tools to shape the app tree. Next, linking and moving between pages covers how users move between these routes.
Check yourself
If a file lives at `app/(shop)/cart/page.tsx`, what is its URL?
`/cart`. The parenthesized folder `(shop)` is a route group and is omitted from the path. It exists only for organization and to hold an optional layout.
Why use a route group instead of just adding a folder?
A normal folder adds a URL segment. A route group lets you gather routes and give them a shared layout while keeping their URLs flat, so `/cart` and `/account` can share a shop layout without becoming `/shop/cart`.
What goes wrong if `app/(marketing)/about/page.tsx` and `app/(shop)/about/page.tsx` both exist?
Both resolve to `/about`, since the groups do not appear in the URL, so Next.js reports a conflict. Each URL must be claimed by exactly one page.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.