Parallel Routes in Next.js — Rendering Dynamic Pages with Named Slots

Parallel Routes in Next.js allow you to render multiple pages simultaneously or conditionally within the same layout. This is ideal for dynamic sections like dashboards, modals, and tabbed interfaces. This article explains how to define named slots, use default.js for fallbacks, manage modals with intercepting routes, and build independent tab groups.

Parallel RoutesNamed Slotsdefault.jsIntercepting Routes

~2 min read · Updated Oct 29, 2025

1. What Are Parallel Routes?


Parallel Routes let you render multiple route segments at the same time or conditionally within a shared layout. They’re perfect for dashboards, feeds, and other dynamic UI sections.


2. Defining Slots with @folder


Use folders prefixed with @ to define slots. For example:

app/@team/page.tsx
app/@analytics/page.tsx

In the root layout, pass these slots as props:

export default function Layout({ children, team, analytics }) {
  return (
    <>
      {children}
      {team}
      {analytics}
    </>
  )
}

3. default.js — Fallback for Unmatched Slots


If a slot isn’t active for the current route, Next.js renders default.js as a fallback. Otherwise, it shows a 404.

// app/@auth/default.tsx
export default function Default() {
  return null
}

4. Navigation Behavior


  • Soft Navigation: Only the active slot changes
  • Hard Navigation: Unmatched slots fall back to default.js or 404

5. Reading Active Segments with useSelectedLayoutSegment


'use client'
import { useSelectedLayoutSegment } from 'next/navigation'

export default function Layout({ auth }) {
  const loginSegment = useSelectedLayoutSegment('auth')
}

6. Conditional Routes Based on User Role


export default function Layout({ user, admin }) {
  const role = checkUserRole()
  return role === 'admin' ? admin : user
}

7. Building Tab Groups with Layout Inside a Slot


To create tabs, define a layout inside the slot:

// app/@analytics/layout.tsx
<nav>
  <Link href="/page-views">Page Views</Link>
  <Link href="/visitors">Visitors</Link>
</nav>
<div>{children}</div>

8. Creating Modals with Parallel + Intercepting Routes


  • Main route: /login
  • Modal: @auth/(.)login/page.tsx
// app/@auth/(.)login/page.tsx
<Modal>
  <Login />
</Modal>

Opening the Modal:

// app/layout.tsx
<Link href="/login">Open modal</Link>
<div>{auth}</div>
<div>{children}</div>

Closing the Modal:

'use client'
import { useRouter } from 'next/navigation'

export function Modal({ children }) {
  const router = useRouter()
  return (
    <>
      <button onClick={() => router.back()}>Close modal</button>
      <div>{children}</div>
    </>
  )
}

Closing with Link:

<Link href="/">Close modal</Link>

Neutral Slot to Close Modal:

// app/@auth/page.tsx
export default function Page() {
  return null
}

9. Independent Loading and Error States


Each slot can have its own loading.js and error.js for better UX and streaming behavior.


Conclusion


Parallel Routes in Next.js are a powerful tool for building dynamic, tabbed, conditional, and modal-driven interfaces. With named slots, default.js fallbacks, and intercepting routes, you can create fluid, shareable, and context-aware user experiences.


Written & researched by Dr. Shahin Siami

Related Articles

Advanced Client-Side Routing and Performance Hooks in Next.js

Next.js provides a rich set of client-side hooks and caching utilities that empower developers to build dynamic, responsive, and secure applications. From reading route parameters to tracking navigation state and reporting performance metrics, this guide walks you through the most important tools available in the App Router.

Continue

Handling Authorization and Caching in Next.js: A Developer’s Guide

Next.js introduces powerful experimental features for access control and smart caching. This guide covers the unauthorized() function for custom 401 handling, unstable_cache for persistent memoization, updateTag for instant cache invalidation, and useLinkStatus for inline navigation feedback. Learn how to use these tools to build secure, performant, and responsive applications.

Continue

redirect and refresh in Next.js — Smart Redirects and Client Refreshing via Server Actions

The redirect function in Next.js allows you to navigate users to a new route, returning either a 307 or 303 HTTP response depending on context. It works in Server Components, Client Components, Route Handlers, and Server Actions. The refresh function is used exclusively within Server Actions to refresh the client router. This article explains how both functions work, with practical examples and key considerations.

Continue

NextRequest and NextResponse in Next.js — Managing Cookies, Headers, Redirects, and Rewrites

Next.js extends the native Web Request and Response APIs with NextRequest and NextResponse, offering powerful tools for managing cookies, headers, redirects, rewrites, and JSON responses. These utilities simplify server-side logic and improve control over routing, personalization, and security. This guide walks through their capabilities with practical examples and best practices.

Continue

headers, ImageResponse, notFound, and permanentRedirect in Next.js — Request Handling, Dynamic Images, Errors, and Redirects

Next.js offers powerful tools for handling HTTP requests and responses in Server Components. The headers function lets you read incoming request headers. ImageResponse allows you to generate dynamic images using JSX and CSS. The notFound function renders a custom 404 page, and permanentRedirect enables permanent redirection to another route. This article explains how to use each feature with practical examples.

Continue

A Complete Guide to Using metadata and generateMetadata in Next.js

In modern versions of Next.js, managing page metadata is more powerful and intuitive than ever. Metadata is automatically injected into the <head> of your pages and plays a vital role in SEO, social sharing, and user experience. This guide explains the two main ways to define metadata: using the static metadata object and the dynamic generateMetadata function.

Continue