Next.js Route Groups
Next.js route groups let you organise routes into logical sections without adding extra segments to the URL. You wrap a folder name in parentheses, like (marketing), and Next.js ignores that name when building the path. This is useful when different parts of your site need different layouts but should share the same URL space .
This tutorial explains the (folderName) syntax, how to give separate layouts to marketing and shop sections, and the caveats around multiple root layouts. You will also learn about private folders and get a short overview of parallel and intercepting routes. If you are new to layouts, read Next.js Pages & Layouts first.
What Are Next.js Route Groups and How Do They Work?
Next.js route groups are folders wrapped in parentheses that organise code without affecting the URL. A file at app/(marketing)/about/page.tsx still resolves to /about, not /(marketing)/about. The parentheses tell Next.js to skip that folder name when building the path .
app/
(marketing)/
about/
page.tsx → /about (not /(marketing)/about)
(shop)/
cart/
page.tsx → /cart
How it works: The folder name inside parentheses is for your organisation only. Next.js reads it during development and build, then removes it from the final URL. This lets you group related routes by team, feature, or section while keeping the public URLs clean and predictable.
How Do You Give Different Layouts to Different Sections?
The main use of route groups is applying different layouts to different parts of your site. Each group folder can contain its own layout.tsx. Pages inside that group inherit the layout. Pages outside do not .
A Marketing Layout
// app/(marketing)/layout.tsx
export default function MarketingLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<section>
<header><h2>Marketing Site</h2></header>
{children}
</section>
);
}
A Shop Layout
// app/(shop)/layout.tsx
export default function ShopLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<section>
<aside><p>Shop Sidebar</p></aside>
<main>{children}</main>
</section>
);
}
Pages Inside Each Group
// app/(marketing)/about/page.tsx
export default function AboutPage() {
return <h1>About Our Company</h1>;
}
// app/(shop)/cart/page.tsx
export default function CartPage() {
return <h1>Your Cart</h1>;
}
Browser shows at /about:
Marketing Site ← marketing layout header
About Our Company ← page content
Browser shows at /cart:
Shop Sidebar ← shop layout sidebar
Your Cart ← page content
How it works: When a request arrives for /about, Next.js finds the matching page inside (marketing) and wraps it with the marketing layout. A request for /cart finds the page inside (shop) and uses the shop layout. The group names never appear in the browser's address bar. Both groups share the root layout at app/layout.tsx if one exists.
How Do Multiple Root Layouts Work and What Is the Caveat?
If you remove the top-level app/layout.tsx and give each route group its own layout.tsx with <html> and <body> tags, you create multiple root layouts. This is useful when two sections need completely different HTML shells .
// app/(marketing)/layout.tsx (acts as root layout)
export default function MarketingRootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
// app/(shop)/layout.tsx (acts as root layout)
export default function ShopRootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
How it works: With no shared root layout, each group provides its own <html> and <body>. Next.js uses the group's layout as the document shell. The important caveat: navigating between two different root layouts triggers a full page reload, not a client-side transition . Layout state is lost. This is the only case where route groups cause a full reload. If you keep a single top-level app/layout.tsx, navigation stays client-side.
What Are Private Folders and When Should You Use Them?
A private folder starts with an underscore, like _components or _utils. Next.js excludes private folders and all their children from routing. They are for organisation only .
app/
_components/
Button.tsx → not a route
dashboard/
page.tsx → /dashboard
_helpers/
format.ts → not a route
How it works: The underscore tells Next.js to ignore the folder when building routes. You can place shared components or utility files next to pages without exposing them as URLs. Colocation already lets you put files in route folders safely, but private folders add an extra signal that these files are implementation details, not routes .
What Is the Folder Convention Cheat Sheet?
Next.js uses several folder naming conventions. Each one changes how the folder behaves. The table below summarises the most important ones for the App Router.
| Convention | Example | Effect |
|---|---|---|
[param] |
app/blog/[slug] |
Dynamic segment. Matches one URL segment and passes it as a param. |
[...param] |
app/docs/[...path] |
Catch-all segment. Matches one or more segments as an array. |
(group) |
app/(marketing) |
Route group. Organises routes without adding a URL segment. |
_folder |
app/_components |
Private folder. Excluded from routing entirely. |
@slot |
app/dashboard/@analytics |
Parallel route slot. Renders alongside the main page in the same layout. |
How it works: Square brackets create dynamic parameters. Parentheses create organisational groups. The underscore hides a folder. The @ symbol creates a named slot for parallel rendering. You will use [param] and (group) most often. Parallel routes and intercepting routes are advanced patterns covered briefly below.
A Short Overview of Parallel and Intercepting Routes
These two conventions appear in advanced Next.js projects, especially for dashboards and modals. You do not need them yet, but recognising the syntax helps when reading existing code.
Parallel Routes with @slot
A folder named @analytics creates a parallel slot. The slot renders alongside the main page.tsx inside the same layout. The layout receives the slot as a prop, like analytics. Slots do not appear in the URL. They are useful for dashboards where different sections load independently .
Intercepting Routes with (..)
An intercepting route uses (.), (..), or (...) to load a route from another part of the app inside the current layout. The common use case is a photo modal. Clicking a photo in a feed opens a modal, but visiting the photo URL directly shows the full page. The interception happens only during client-side navigation .
Both patterns rely on route groups and layouts working together. They are optional features. Most projects can be built with dynamic routes and regular layouts alone.
Common Mistakes and Best Practices
- Two groups resolving to the same URL path.
(marketing)/about/page.tsxand(shop)/about/page.tsxboth resolve to/about. Next.js throws an error because two files cannot serve the same route . Keep each public URL unique across all groups. - Expecting client-side navigation between multiple root layouts. If you remove the top-level layout and give each group its own
<html>shell, navigating between groups causes a full page reload. Keep a single root layout unless you truly need separate HTML documents . - Using route groups for URL structure. Groups do not change the URL. If you need a URL segment like
/shop, create a regular folder namedshop, not a group named(shop). - Forgetting that the home page must live inside a group when using multiple root layouts. With no top-level layout, define
app/(marketing)/page.tsxfor the/route . Otherwise the home page has no root layout to render. - Overusing groups for small projects. A simple site with one layout does not need route groups. Add them when two sections genuinely need different layouts or when you want to separate code by feature.
Real-World Example: Marketing and Shop with Separate Layouts
This example creates two route groups with different layouts and two pages whose URLs do not include the group names.
app/
layout.tsx ← shared root layout (optional)
(marketing)/
layout.tsx ← marketing header
about/
page.tsx → /about
(shop)/
layout.tsx ← shop sidebar
cart/
page.tsx → /cart
// app/(marketing)/layout.tsx
export default function MarketingLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<section>
<header><h2>Welcome to Our Brand</h2></header>
{children}
</section>
);
}
// app/(shop)/layout.tsx
export default function ShopLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<section>
<aside><p>Categories</p></aside>
<main>{children}</main>
</section>
);
}
// app/(marketing)/about/page.tsx
export default function AboutPage() {
return <h1>Our Story</h1>;
}
// app/(shop)/cart/page.tsx
export default function CartPage() {
return <h1>Shopping Cart</h1>;
}
Browser shows at /about:
Welcome to Our Brand ← marketing layout
Our Story ← page content
Browser shows at /cart:
Categories ← shop layout
Shopping Cart ← page content
Line-by-line explanation: The (marketing) folder wraps the about page. Its layout adds a brand header. The (shop) folder wraps the cart page. Its layout adds a sidebar. The URLs are /about and /cart because parentheses exclude the folder names from the path. Both pages share the root layout at app/layout.tsx if it exists. Navigation between /about and /cart stays client-side because both groups use the same root layout.
Summary
- Next.js route groups use
(folderName)to organise routes without adding URL segments. - Each group can have its own
layout.tsx, so marketing and app sections can look different while sharing URL space. - Multiple root layouts are possible by removing the top-level layout, but navigating between them triggers a full page reload.
- Private folders start with
_and are excluded from routing. Use them for components and utilities. - Two groups must never resolve to the same URL path. Next.js throws an error if they do.
- Parallel routes (
@slot) and intercepting routes ((..)) are advanced conventions built on the same folder system.
Now that you can organise routes into groups, continue to Next.js Middleware to learn how to run code before a request completes.
Frequently Asked Questions
Do route groups change the URL of a page?
No. The parentheses in a folder name like (marketing) tell Next.js to skip that folder when building the URL. A page at app/(marketing)/about/page.tsx resolves to /about, not /(marketing)/about. Route groups are for organisation and layout control only.
Can I have a route group and a normal folder with the same name?
Yes, but they must not resolve to the same URL. A folder (shop) and a folder shop are different. The group (shop) adds no URL segment, while shop adds /shop. If both contain a page that resolves to the same path, Next.js throws a build error.
Why does navigation between two sections cause a full page reload?
This happens only when you use multiple root layouts. If you remove app/layout.tsx and give each route group its own layout with <html> and <body> tags, Next.js treats each group as a separate document. Switching between them requires a full page load because the browser must load a new HTML document.
When should I use a private folder instead of a route group?
Use a private folder (_folderName) when you want to store files that should never become routes, like shared components or utility functions. Use a route group ((folderName)) when you want to organise actual pages and give them a shared layout. Private folders are excluded from routing entirely.
Are parallel routes required for a normal Next.js app?
No. Parallel routes with @slot folders are an advanced feature for dashboards and complex layouts where multiple sections render at the same time. Most applications work fine with regular pages and layouts. You can learn parallel routes later when you need to build a dashboard with independent loading states.
Practice Exercises
Easy: Create a Marketing Route Group
Create a folder app/(marketing)/contact/page.tsx that renders a heading. Confirm the URL is /contact and not /(marketing)/contact.
Show solution
// app/(marketing)/contact/page.tsx
export default function ContactPage() {
return <h1>Contact Us</h1>;
}
The parentheses remove the folder name from the URL, so the route is /contact.
Easy: Add a Layout to a Route Group
Add app/(marketing)/layout.tsx that shows a heading Marketing Header above the children. Verify it appears on the contact page but not on other pages.
Show solution
// app/(marketing)/layout.tsx
export default function MarketingLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<section>
<h2>Marketing Header</h2>
{children}
</section>
);
}
The layout applies only to pages inside the (marketing) group.
Medium: Explain the Conflict Error
A developer creates app/(marketing)/about/page.tsx and app/(shop)/about/page.tsx. What error does Next.js show and why?
Show solution
// Error: You cannot have two parallel pages that resolve to the same path.
// Both (marketing)/about and (shop)/about resolve to /about.
Route groups do not change the URL. Two groups cannot contain pages with the same public path.
Challenge: Build Two Groups with Separate Layouts
Create a (blog) group with a layout that shows a sidebar, and a (docs) group with a layout that shows a top bar. Add one page to each. Confirm the URLs do not include the group names.
Show solution
app/
(blog)/
layout.tsx
post/
page.tsx → /post
(docs)/
layout.tsx
guide/
page.tsx → /guide
// app/(blog)/layout.tsx
export default function BlogLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<section>
<aside><p>Blog Sidebar</p></aside>
<main>{children}</main>
</section>
);
}
// app/(docs)/layout.tsx
export default function DocsLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<section>
<header><p>Docs Top Bar</p></header>
{children}
</section>
);
}
// app/(blog)/post/page.tsx
export default function PostPage() {
return <h1>Blog Post</h1>;
}
// app/(docs)/guide/page.tsx
export default function GuidePage() {
return <h1>Guide</h1>;
}
Both pages resolve to /post and /guide without the group names in the URL.
Written by Shaikh Abdul Shahid
A Full-Stack Developer with experience in PHP, Laravel, JavaScript, and React.
Founder of Online Learner, sharing practical knowledge and programming tutorials.
Building and maintaining real-world web applications since 2017.
Your Feedback
Help us improve by sharing your thoughts.
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
