Skip to content
RoutingChapter 8 / 34Intermediate4 min read

Route Groups & Private Folders

Next.js route groups and private folders: organize routes with (group) folders without changing the URL, and keep files out of routing with _folder.

On this page

1. What are route groups and private folders?

Both exist for organization. With a route group you can group routes and give each group its own layout. With a private folder you can keep components, utils and helpers close to a route without worrying that they will turn into routes.

2. Why does it matter?

Without groupsWith route groups
Marketing and dashboard share one layoutEach group has its own layout
URL gets longer just to group pages(marketing) does not appear in the URL
All routes in one big pileFolders organized by team and feature
Helpers live far away from the app_components is colocated with the route

3. Where is it used?

SituationStructure
A separate header for marketing pagesapp/(marketing)/layout.tsx
A sidebar layout for the dashboardapp/(dashboard)/layout.tsx
Auth pages without the navbarapp/(auth)/login/page.tsx
One layout on only some routesapp/(shop)/layout.tsx for shop routes only
Components that belong to one routeapp/blog/_components/PostCard.tsx

4. How does it work?

Route group disappears from the URL
app/(marketing)/about/page.tsx
Next.js ignores the part in parentheses
URL: /about
Layout: app/(marketing)/layout.tsx

The rule for private folders is simple: a folder that starts with an underscore, and all its child folders, are left out of routing, even if there is a page.tsx inside.

bash
app/
  layout.tsx
  (marketing)/
    layout.tsx
    page.tsx
    about/page.tsx
  (dashboard)/
    layout.tsx
    dashboard/page.tsx
    _components/
      Sidebar.tsx
      StatsCard.tsx
  (auth)/
    login/page.tsx
FileURL
app/(marketing)/page.tsx/
app/(marketing)/about/page.tsx/about
app/(dashboard)/dashboard/page.tsx/dashboard
app/(auth)/login/page.tsx/login
app/(dashboard)/_components/StatsCard.tsxNo URL

5. Code example

Layout of a group

tsx
import { Sidebar } from "./_components/Sidebar";

export default function DashboardGroupLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <div className="grid grid-cols-[240px_1fr]">
      <Sidebar />
      <main>{children}</main>
    </div>
  );
}

Component in a private folder

tsx
import Link from "next/link";

export function Sidebar() {
  return (
    <aside>
      <Link href="/dashboard">Overview</Link>
      <Link href="/dashboard/orders">Orders</Link>
    </aside>
  );
}

How does the code work?

PartMeaning
(dashboard)/layout.tsxWraps only the routes in this group
(dashboard)Does not appear in the URL
_components/Sidebar.tsxA private folder, never becomes a route
./_components/SidebarA relative import, colocated with the route

Interview tip

"What is the difference between a route group and a private folder?" The routes inside a route group work normally, only its name is removed from the URL. Nothing inside a private folder ever becomes a route.

6. Common mistakes

Mistake: Creating pages with the same URL in two groups

Why? (marketing)/about and (shop)/about both produce /about, which causes a conflict error.

Better: Define each URL in only one place. Groups are only for organization.

Mistake: Creating a page inside a private folder and expecting a route

Why? A folder that starts with an underscore, and its children, stay outside routing.

Better: Keep routes in normal or group folders. Use _folder only for helpers.

Mistake: Forgetting html and body in multiple root layouts

Why? Once the top-level layout is removed, each group layout is the root and it needs html and body.

Better: Always render the html and body tags in every group root layout.

7. What to learn before and after

Final quick revision

PointDetail
Route group(name), does not appear in the URL
BenefitA separate layout for each group
Private folder_name, outside routing
ColocationKeeping components next to their route
Multiple root layoutsFull page load between groups