Falytom logoFALYTOM
Games
ToolsUI ComponentsServicesProductsAbout
menu
  1. Home
  2. /Web Development
  3. /Nextjs
  4. /Route Groups
Your Progress0%
0 of 70 completed

NextJS Topics

Getting Started

  • What is Next.js?
  • Next.js vs React - Key Differences
  • Creating Your First Next.js 15 Project
  • Next.js Project Structure Explained
  • App Router vs Pages Router

Routing Fundamentals

  • File-Based Routing Basics
  • Creating Pages with page.tsx
  • Dynamic Routes and Route Parameters
  • Catch-All and Optional Catch-All Routes
  • Route Groups for Organization
  • Parallel Routes
  • Intercepting Routes

Layouts and Pages

  • Understanding Layouts
  • Root Layout and Global Configuration
  • Nested Layouts
  • Templates vs Layouts
  • Loading States with loading.tsx
  • Error Handling with error.tsx

Server and Client Components

  • Understanding Server Components
  • Client Components with 'use client'
  • When to Use Server vs Client Components
  • Component Composition Patterns
  • Passing Props Between Server and Client
  • Server Component Patterns and Best Practices

Data Fetching

  • Fetching Data in Server Components
  • Parallel and Sequential Data Fetching
  • Data Fetching Patterns and Strategies
  • Caching and Revalidation
  • Revalidate and Cache Tags
  • Handling Loading and Error States in Data Fetching

Navigation and Links

  • Link Component Basics
  • useRouter Hook for Programmatic Navigation
  • usePathname and useSearchParams Hooks
  • Active Links and Navigation States
  • Redirects and Navigation Guards

Styling in Next.js

  • CSS Modules in Next.js
  • Tailwind CSS Setup and Configuration
  • Global Styles and CSS Variables
  • Next.js Font Optimization

Images and Media

  • Next.js Image Component Basics
  • Image Optimization and Best Practices
  • Working with Static Assets

Forms and Data Mutations

  • Understanding Server Actions
  • Form Handling with Server Actions
  • Form Validation and Error Handling
  • useFormStatus and useFormState Hooks
  • Revalidating Data After Mutations
  • Optimistic Updates

Metadata and SEO

  • Static Metadata Configuration
  • Dynamic Metadata Generation
  • Open Graph and Social Media Cards
  • Sitemap and Robots.txt

API Routes and Route Handlers

  • Route Handlers Introduction
  • GET and POST Request Handlers
  • Dynamic API Routes
  • Request and Response Objects
  • API Error Handling and Status Codes

Middleware and Advanced Features

  • Introduction to Middleware
  • Authentication with Middleware
  • Environment Variables and Configuration
  • Streaming and Suspense
  • Not Found and Global Error Pages

Deployment and Optimization

  • Understanding Static and Dynamic Rendering
  • generateStaticParams for Static Generation
  • Build and Production Optimization
  • Deploying to Vercel
  • Alternative Deployment Options
  • Performance Monitoring and Analytics

Real-World Projects

  • Project 1: E-commerce Product Catalog
  • Project 2: Dashboard with Authentication

Route Groups for Organization

Organizing routes with parentheses without affecting URLs

As your Next.js application grows, you'll want to organize routes into logical sections without cluttering your URLs. Route groups let you do exactly that—wrap a folder name in parentheses like (marketing), and it becomes invisible in the URL while keeping your file structure clean and organized. Even better, each group can have its own layout!

The Organization Problem

Imagine you're building a large application with different sections:

  • Marketing pages (homepage, about, contact)
  • E-commerce pages (products, cart, checkout)
  • Dashboard pages (analytics, settings, users)
  • Authentication pages (login, register, forgot password)

Without route groups, you'd have everything at the root level:

PLAINTEXT
app/
  page.tsx                 → /
  about/
    page.tsx               → /about
  products/
    page.tsx               → /products
  dashboard/
    page.tsx               → /dashboard
  login/
    page.tsx               → /login
  settings/
    page.tsx               → /settings
  
  # Everything is mixed together!
  # Hard to see which pages belong to which section
  # Can't apply different layouts to different sections

Problems with this structure:

  • No visual organization—all routes look equal
  • Can't tell which pages belong together
  • Hard to apply different layouts to different sections
  • Difficult to navigate in large projects

The Solution: Route Groups

Route groups use parentheses (name) to organize routes without affecting the URL:

PLAINTEXT
app/
  (marketing)/
    page.tsx               → /
    about/
      page.tsx             → /about
  (shop)/
    products/
      page.tsx             → /products
  (dashboard)/
    dashboard/
      page.tsx             → /dashboard
    settings/
      page.tsx             → /settings
  (auth)/
    login/
      page.tsx             → /login
  
  # Organized into logical groups!
  # But URLs stay the same—no /marketing/ or /shop/ in URL

The Magic of Parentheses

Folders wrapped in parentheses (group) are completely invisible to the routing system. They exist only for organization and don't create URL segments.

Creating Your First Route Group

Let's organize a website with marketing and shop sections:

Step 1: Create Route Group Folders

PLAINTEXT
app/
  (marketing)/          ← Route group (not in URL)
  (shop)/               ← Route group (not in URL)

Step 2: Add Pages to Each Group

PLAINTEXT
app/
  (marketing)/
    page.tsx            → /
    about/
      page.tsx          → /about
    contact/
      page.tsx          → /contact
  (shop)/
    products/
      page.tsx          → /products
    cart/
      page.tsx          → /cart

Step 3: Create the Marketing Homepage

app/(marketing)/page.tsx
export default function HomePage() {
  return (
    <div className="container mx-auto px-4 py-8">
      <h1 className="text-5xl font-bold mb-6">Welcome to Our Site</h1>
      <p className="text-xl text-gray-600">
        This is the homepage in the marketing group
      </p>
    </div>
  );
}

// This page is at the URL: /
// NOT at /marketing/ ← the (marketing) folder doesn't appear!

Step 4: Create Shop Pages

app/(shop)/products/page.tsx
export default function ProductsPage() {
  return (
    <div className="container mx-auto px-4 py-8">
      <h1 className="text-4xl font-bold mb-6">Our Products</h1>
      <p>Browse our amazing product catalog</p>
    </div>
  );
}

// This page is at the URL: /products
// NOT at /shop/products ← the (shop) folder doesn't appear!

🎯 Key Point

The route group names (marketing) and (shop) never appear in URLs. They're purely for organizing your code in the file system!

Different Layouts Per Route Group

One of the most powerful features of route groups is that each group can have its own layout:

Marketing Layout (Simple)

app/(marketing)/layout.tsx
import Link from 'next/link';

export default function MarketingLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <div>
      {/* Simple header for marketing pages */}
      <header className="bg-white border-b">
        <nav className="container mx-auto px-4 py-4 flex items-center justify-between">
          <Link href="/" className="text-2xl font-bold">
            Brand
          </Link>
          <div className="flex gap-6">
            <Link href="/about" className="hover:text-blue-600">
              About
            </Link>
            <Link href="/contact" className="hover:text-blue-600">
              Contact
            </Link>
            <Link href="/products" className="hover:text-blue-600">
              Products
            </Link>
          </div>
        </nav>
      </header>
      
      {/* Page content */}
      <main>{children}</main>
      
      {/* Simple footer */}
      <footer className="bg-gray-100 py-8 mt-12">
        <div className="container mx-auto px-4 text-center text-gray-600">
          © 2024 Your Company
        </div>
      </footer>
    </div>
  );
}

Shop Layout (With Cart Badge)

app/(shop)/layout.tsx
"use client";

import Link from 'next/link';
import { useState } from 'react';

export default function ShopLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const [cartCount] = useState(3);
  
  return (
    <div>
      {/* Header with cart for shop pages */}
      <header className="bg-blue-600 text-white">
        <nav className="container mx-auto px-4 py-4 flex items-center justify-between">
          <Link href="/" className="text-2xl font-bold">
            Shop
          </Link>
          <div className="flex items-center gap-6">
            <Link href="/products" className="hover:underline">
              Products
            </Link>
            <Link href="/cart" className="relative">
              🛒 Cart
              {cartCount > 0 && (
                <span className="absolute -top-2 -right-2 bg-red-500 text-white text-xs rounded-full w-5 h-5 flex items-center justify-center">
                  {cartCount}
                </span>
              )}
            </Link>
          </div>
        </nav>
      </header>
      
      {/* Page content */}
      <main className="min-h-screen">{children}</main>
      
      {/* Shop footer with links */}
      <footer className="bg-gray-900 text-white py-8">
        <div className="container mx-auto px-4">
          <div className="grid grid-cols-3 gap-8">
            <div>
              <h3 className="font-bold mb-4">Shop</h3>
              <Link href="/products">Products</Link>
            </div>
            <div>
              <h3 className="font-bold mb-4">Help</h3>
              <Link href="/contact">Contact</Link>
            </div>
            <div>
              <h3 className="font-bold mb-4">Legal</h3>
              <Link href="/terms">Terms</Link>
            </div>
          </div>
        </div>
      </footer>
    </div>
  );
}

Multiple Layouts in One App

With route groups, pages in (marketing) get the marketing layout, pages in (shop) get the shop layout—all automatically! No configuration needed.

Visualizing Route Group Structure

Basic Route Groups Example

Three route groups with different layouts

appImportant

Select a file or folder to see details

What gets created:

File PathURL RouteLayout Used
app/(marketing)/page.tsx/(marketing) layout
app/(marketing)/about/page.tsx/about(marketing) layout
app/(shop)/products/page.tsx/products(shop) layout
app/(shop)/cart/page.tsx/cart(shop) layout
app/(dashboard)/dashboard/page.tsx/dashboard(dashboard) layout
app/(dashboard)/settings/page.tsx/settings(dashboard) layout

Nested Route Groups

You can nest route groups inside each other for even more organization:

Advanced: Nested Route Groups

Route groups can be nested for fine-grained organization

appImportant

Select a file or folder to see details

In this structure:

  • (auth) has its own minimal layout for login/register
  • (main) has a full layout for the main app
  • (public) inside (main) groups public pages
  • (protected) inside (main) groups pages that need auth

All layouts stack—pages get all parent layouts!

Common Use Cases

1. Authentication Layout

Separate auth pages with a centered, minimal layout:

PLAINTEXT
app/
  (auth)/
    layout.tsx          ← Centered layout, no header/footer
    login/
      page.tsx          → /login
    register/
      page.tsx          → /register
    forgot-password/
      page.tsx          → /forgot-password
app/(auth)/layout.tsx
export default function AuthLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <div className="min-h-screen flex items-center justify-center bg-gray-50">
      <div className="max-w-md w-full">
        {/* Logo */}
        <div className="text-center mb-8">
          <h1 className="text-3xl font-bold">Your App</h1>
        </div>
        
        {/* Auth form */}
        <div className="bg-white p-8 rounded-lg shadow-lg">
          {children}
        </div>
        
        {/* Footer links */}
        <div className="text-center mt-6 text-sm text-gray-600">
          <a href="/privacy" className="hover:underline">Privacy</a>
          {' · '}
          <a href="/terms" className="hover:underline">Terms</a>
        </div>
      </div>
    </div>
  );
}

2. Dashboard with Sidebar

PLAINTEXT
app/
  (dashboard)/
    layout.tsx          ← Layout with sidebar
    dashboard/
      page.tsx          → /dashboard
    analytics/
      page.tsx          → /analytics
    settings/
      page.tsx          → /settings
    users/
      page.tsx          → /users

3. Multi-Tenant Apps

PLAINTEXT
app/
  (admin)/
    layout.tsx          ← Admin layout with admin nav
    users/
      page.tsx          → /users
  (customer)/
    layout.tsx          ← Customer layout with customer nav
    orders/
      page.tsx          → /orders

4. Different Landing Pages

PLAINTEXT
app/
  (landing-v1)/
    page.tsx            → / (A/B test version 1)
  (landing-v2)/
    page.tsx            → / (A/B test version 2)
  
  # Note: You can't have both serve / at the same time
  # This is for testing locally, not production

Handling Route Conflicts

Since route groups are invisible to URLs, you could accidentally create conflicts:

❌ Conflicting Routes

PLAINTEXT
app/
  (marketing)/
    about/
      page.tsx          → /about
  (shop)/
    about/
      page.tsx          → /about
    
# ERROR! Both try to create /about
# Next.js will throw an error at build time

✅ Solution: Use Unique Route Names

PLAINTEXT
app/
  (marketing)/
    about/
      page.tsx          → /about
  (shop)/
    about-us/
      page.tsx          → /about-us
    
# Works! Different URLs for each page

⚠️ Watch Out for Conflicts

Next.js will catch route conflicts at build time and show an error. Make sure each final URL path is unique across all route groups!

Route Groups Without Layouts

Route groups don't have to have layouts—they're useful for organization alone:

PLAINTEXT
app/
  (features)/           ← No layout.tsx, just organization
    feature-a/
      page.tsx
    feature-b/
      page.tsx
  (legal)/              ← No layout.tsx, just organization
    privacy/
      page.tsx
    terms/
      page.tsx

These pages will use the root layout or any parent layout, but the grouping helps you:

  • Visually organize related pages
  • Keep your file structure clean
  • Make it easier to find related pages
  • Group pages by feature, team, or purpose

Practice: Build a Complete Site Structure

Complete Site Structure with Route Groups

A real-world example showing how to organize a full application

structure.txt

Output Preview

Click "Run Code" to see the output

🎯 Try This Exercise

Create this structure in your Next.js project:

  1. Create (marketing) group with home, about, contact pages
  2. Create (shop) group with products and cart pages
  3. Give each group its own layout with different styling
  4. Test that URLs work without the group names

Best Practices

1. Use Descriptive Group Names

Good:

PLAINTEXT
app/
  (marketing)/
  (shop)/
  (dashboard)/
  (auth)/

Less clear:

PLAINTEXT
app/
  (group1)/
  (section)/
  (pages)/
  (a)/

2. Group by Purpose, Not by Technology

Good: Group by what the pages do

PLAINTEXT
app/
  (onboarding)/      ← Purpose: new user onboarding
  (checkout)/        ← Purpose: purchase flow
  (admin)/           ← Purpose: admin tools

Less useful: Group by implementation

PLAINTEXT
app/
  (client-components)/
  (server-components)/
  (api-routes)/

3. Don't Over-Organize

Start simple. Add route groups only when you need them:

  • Do you have multiple distinct sections? → Use route groups
  • Do different sections need different layouts? → Use route groups
  • Do you have 50+ pages? → Use route groups for organization
  • Do you have 5 pages? → Probably don't need route groups yet

4. Combine with Other Patterns

Route groups work great with other routing patterns:

PLAINTEXT
app/
  (shop)/
    products/
      [id]/             ← Dynamic route
        page.tsx
    categories/
      [...slug]/        ← Catch-all route
        page.tsx

Private Folders vs Route Groups

FeaturePrivate Folders (_folder)Route Groups (folder)
PurposeExclude from routing completelyOrganize routes without affecting URLs
In URL?No (ignored entirely)No (but children are routes)
Can have page.tsx?No effect (won't be a route)Yes (creates route)
Can have layout.tsx?No effectYes (applies to children)
Use CaseShared utilities, componentsOrganize routes into sections

Key Takeaways

  • Route groups use parentheses - (marketing), (shop), (auth)
  • Invisible in URLs - they don't create URL segments
  • Purely for organization - keep your file structure clean
  • Each group can have its own layout - different sections, different layouts
  • Can be nested - create hierarchical organization
  • Watch for conflicts - same URL from different groups = error
  • Start simple - add groups as your app grows
  • Name descriptively - use names that explain the purpose

What's Next?

You've mastered route organization! You now know how to create clean, well-structured applications using route groups. But there's one more advanced routing concept to learn: parallel routes.

Parallel routes let you render multiple pages in the same layout simultaneously—perfect for dashboards with multiple sections, modals that preserve the page behind them, or complex UIs with independent sections. This is an advanced topic, but incredibly powerful!

🎨 Route Groups Are Your Friend

As your application grows, route groups become increasingly valuable. They keep your codebase organized, make it easy to apply different layouts to different sections, and help team members quickly understand your app's structure. Use them liberally!

Test Your Understanding

Question 1 of 4

What is the primary purpose of route groups?

Learn how to organize Next.js routes with (folder) syntax without affecting URLs!

Previous
Catch-All and Optional Catch-All Routes
Next
Parallel Routes

Master Advanced Next.js Routing

Join 2,000+ developers mastering Next.js. Get the next lesson on parallel routes delivered to your inbox - 100% FREE.

You might also like

UI Components

Ready-made components for your projects

Developer Tools

Boost productivity with handy generators

HTML Game

Learn HTML concepts through interactive gameplay

Join Our Web Development Training Program

Master frontend & backend development with hands-on projects.

NextJS Tutorials

0 of 70 completed

Your Progress0%

Topics

Getting Started

  • What is Next.js?
  • Next.js vs React - Key Differences
  • Creating Your First Next.js 15 Project
  • Next.js Project Structure Explained
  • App Router vs Pages Router

Routing Fundamentals

  • File-Based Routing Basics
  • Creating Pages with page.tsx
  • Dynamic Routes and Route Parameters
  • Catch-All and Optional Catch-All Routes
  • Route Groups for Organization
  • Parallel Routes
  • Intercepting Routes

Layouts and Pages

  • Understanding Layouts
  • Root Layout and Global Configuration
  • Nested Layouts
  • Templates vs Layouts
  • Loading States with loading.tsx
  • Error Handling with error.tsx

Server and Client Components

  • Understanding Server Components
  • Client Components with 'use client'
  • When to Use Server vs Client Components
  • Component Composition Patterns
  • Passing Props Between Server and Client
  • Server Component Patterns and Best Practices

Data Fetching

  • Fetching Data in Server Components
  • Parallel and Sequential Data Fetching
  • Data Fetching Patterns and Strategies
  • Caching and Revalidation
  • Revalidate and Cache Tags
  • Handling Loading and Error States in Data Fetching

Navigation and Links

  • Link Component Basics
  • useRouter Hook for Programmatic Navigation
  • usePathname and useSearchParams Hooks
  • Active Links and Navigation States
  • Redirects and Navigation Guards

Styling in Next.js

  • CSS Modules in Next.js
  • Tailwind CSS Setup and Configuration
  • Global Styles and CSS Variables
  • Next.js Font Optimization

Images and Media

  • Next.js Image Component Basics
  • Image Optimization and Best Practices
  • Working with Static Assets

Forms and Data Mutations

  • Understanding Server Actions
  • Form Handling with Server Actions
  • Form Validation and Error Handling
  • useFormStatus and useFormState Hooks
  • Revalidating Data After Mutations
  • Optimistic Updates

Metadata and SEO

  • Static Metadata Configuration
  • Dynamic Metadata Generation
  • Open Graph and Social Media Cards
  • Sitemap and Robots.txt

API Routes and Route Handlers

  • Route Handlers Introduction
  • GET and POST Request Handlers
  • Dynamic API Routes
  • Request and Response Objects
  • API Error Handling and Status Codes

Middleware and Advanced Features

  • Introduction to Middleware
  • Authentication with Middleware
  • Environment Variables and Configuration
  • Streaming and Suspense
  • Not Found and Global Error Pages

Deployment and Optimization

  • Understanding Static and Dynamic Rendering
  • generateStaticParams for Static Generation
  • Build and Production Optimization
  • Deploying to Vercel
  • Alternative Deployment Options
  • Performance Monitoring and Analytics

Real-World Projects

  • Project 1: E-commerce Product Catalog
  • Project 2: Dashboard with Authentication
Falytom logoFALYTOM

Learn technologies like HTML, CSS, JavaScript, React, NodeJS and more through interactive games, tutorials, components and free tools. Transform your businesses with AI chatbots, SEO-optimized websites, and professional development services.

© 2025 Tomilola Group
  • Facebook logo
  • Twitter logo
  • Instagram logo
  • LinkedIn logo
  • GitHub logo
  • YouTube logo