Next.js Curriculum
EasyFile-System Conventions100% Free20 min read

Route Groups and Multiple Root Layouts

The 30-Second Interview Answer

Route groups wrap folder names in parentheses, such as (marketing) and (dashboard), organizing files and layouts without affecting the public URL path. They allow developers to create multiple root layouts with completely different <html> and <body> tags in the same application.

Learning Objectives

Organize complex codebases using parentheses syntax (folder) without altering URLs.

Implement multiple independent root layouts for distinct application surfaces.

Understand navigation transitions between different root layouts (full page reloads).

Prevent route resolution collisions when using route groups.

Prerequisites & Background Knowledge
App Router folder structureRoot layout requirements

Why Interviewers Care

Standard architectural question when designing applications with distinct public marketing sites and logged-in consoles.

The Challenge

How do route groups (folder) work in Next.js App Router? How do you configure multiple root layouts for public marketing and authenticated console surfaces within the same codebase?

Code Architecture & Implementation

1// File Structure:
2// app/
3// ├── (marketing)/
4// │ ├── layout.tsx <- Root Layout 1 (Public marketing navbar & footer)
5// │ ├── page.tsx <- Maps to URL: /
6// │ └── pricing/
7// │ └── page.tsx <- Maps to URL: /pricing
8// └── (dashboard)/
9// ├── layout.tsx <- Root Layout 2 (Authenticated sidebar & console header)
10// └── console/
11// └── page.tsx <- Maps to URL: /console
12
13// app/(marketing)/layout.tsx
14export default function MarketingRootLayout({ children }: { children: React.ReactNode }) {
15 return (
16 <html lang="en">
17 <body className="marketing-theme">
18 <header className="public-nav">Brand Marketing Nav</header>
19 {children}
20 <footer>Marketing Footer</footer>
21 </body>
22 </html>
23 );
24}
25
26// app/(dashboard)/layout.tsx
27export default function DashboardRootLayout({ children }: { children: React.ReactNode }) {
28 return (
29 <html lang="en">
30 <body className="dashboard-console-theme">
31 <aside className="admin-sidebar">Console Nav</aside>
32 <div className="console-content">{children}</div>
33 </body>
34 </html>
35 );
36}

Architectural Explanation

Route Groups Syntax & Mechanics

Wrapping a folder name in parentheses (groupName) instructs the Next.js router to omit that folder segment from the URL path:

  • app/(marketing)/about/page.tsx $\rightarrow$ /about
  • app/(shop)/cart/page.tsx $\rightarrow$ /cart

Multiple Root Layouts

By deleting the top-level app/layout.tsx file, developers can define separate root layouts inside top-level route groups:

  1. Surface Isolation: app/(marketing)/layout.tsx can render public headers, Google Analytics tags, and marketing stylesheets.
  2. Console Isolation: app/(admin)/layout.tsx can load an entirely different authenticated theme, dark mode defaults, and enterprise toolbars.
  3. Caveat on Navigation: Navigating between routes governed by different root layouts triggers a full document reload (hard navigation) rather than a soft client transition, because the entire <html> and <body> DOM structure changes.

Common Mistakes & Anti-Patterns

Creating route collisions, such as defining app/(marketing)/about/page.tsx and app/(shop)/about/page.tsx (causes build error: multiple routes resolve to /about).

Forgetting that every root layout in a multi-root application must define its own <html> and <body> tags.

Expecting soft client-side transitions when navigating across different root layout boundaries.

Interview Follow-Up Traps

Interviewer asks: "If you have multiple root layouts, does navigating between them preserve React client state?" Trap answer: Yes, Next.js handles it. Correct answer: No! Navigating across different root layouts triggers a full browser reload because the root <html> and <body> nodes are replaced.

Interviewer asks: "Can you nest route groups inside other route groups?" Trap answer: No, only at the root. Correct answer: Yes, route groups can be nested at any depth in the folder tree to organize layouts or middleware matcher groupings.

Frequently Asked Questions

Do route groups affect SEO or search engine ranking?

No. Route groups are purely internal file-system organization tools and are completely invisible in public URLs and canonical links.

To share components, TypeScript types, and server actions within a single unified codebase while maintaining distinct layout visual hierarchies.

No directly, because route group folder names are omitted from the request URL pathname that middleware inspects.

Wrap any descriptive name in parentheses: (auth), (dashboard), (shop).

Next.js throws a build-time route collision error during compilation.