Course contentsShow
← React
Lesson 1890 of 2,39643. RoutingFree lesson

Route Groups and Layout Nesting

Organizing routes with (folders) that don't affect URLs and sharing layouts across multiple route segments.

Route Groups and Layout Nesting

What you'll learn: How to organize Next.js App Router routes into groups that don't affect URLs while sharing layouts across multiple segments.

The Core Idea

In Next.js App Router, route groups let you organize your file structure logically without adding segments to the URL path. You create them by wrapping folder names in parentheses: (folderName). This is powerful for two key scenarios: organizing related routes together and applying shared layouts to specific route subsets.

Think of route groups like sections in a filing cabinet that help you stay organized, but visitors never see those section labels when accessing files.

How It Works

A folder named (marketing) creates a route group. Files inside follow normal routing rules, but (marketing) doesn't appear in the URL:

app/
  (marketing)/
    about/
      page.tsx        → /about (not /marketing/about)
    pricing/
      page.tsx        → /pricing
    layout.tsx        → Shared layout for marketing pages
  (shop)/
    products/
      page.tsx        → /products
    cart/
      page.tsx        → /cart
    layout.tsx        → Different layout for shop pages

Each route group can have its own layout.tsx, letting you create distinct layouts for different sections of your app without nesting URL segments. The (marketing) routes share one layout, while (shop) routes share another—both at the same URL hierarchy level.

When to Use This

Route groups shine when you need multiple root-level layouts (like a marketing site vs. a dashboard) or want to organize large route collections by feature without polluting URLs. You can even have multiple route groups at the same level, each with its own layout styling, navigation, or data fetching logic.

Key Takeaway: Route groups (name) organize your routes and enable layout nesting without adding URL segments—perfect for maintaining clean URLs while structuring complex applications with distinct layout needs.