Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 72 ยท Routing

Parallel and Intercepting Routes

Render several pages in one layout with @slot folders, add default.tsx fallbacks, and build URL-driven modals with intercepting routes. Soft vs hard navigation explained.

Until now, one URL showed one page inside a chain of layouts. Real interfaces are busier. A dashboard has a chart, a team list and a main panel that each load at their own speed and fail on their own. A photo gallery opens a picture in a modal that has its own address, so the link can be shared, yet clicking it inside the gallery should not leave the gallery. Neither fits "one URL, one page".

The App Router has two features for these cases. Parallel routes (folders starting with @) let one layout render several independent pages side by side. Intercepting routes (folders starting with (.), (..) or (...)) let a link show a different page than the one it points to, as long as the visitor navigates from inside the app. Together they give you URL-driven modals. This lesson explains both, the soft versus hard navigation difference that makes everything work, and the file you must not forget: default.tsx. It builds on Pages and Layouts, Linking and Navigation and Dynamic Routes.

Real framework or stand-in? The folder trees and tsx code are real Next.js and read-only. The live examples are React stand-ins with a tiny slot engine written for this lesson. They imitate the rules described here (slots keep their last state on soft navigation, default.tsx appears on hard navigation, interception only happens on soft navigation). The real implementation lives inside the Next.js router and differs in detail.

Two features, one idea

@slot One layout renders several pages at once.
(.)folder A link shows a different page in place.

Slots are for composition. Interception is for modals and previews.

1 / 2

Parallel routes with @slots

A folder whose name begins with @ is a slot. It is not a URL segment: app/dashboard/@analytics/page.tsx does not create /dashboard/@analytics. Instead, the slot becomes a prop of the layout one level above it, next to the normal children:

TEXT
app/
  dashboard/
    layout.tsx           receives children, analytics and team
    page.tsx             -> /dashboard         (this is the children slot)
    settings/
      page.tsx           -> /dashboard/settings
    @analytics/
      page.tsx           shown at /dashboard
      loading.tsx
      default.tsx
    @team/
      page.tsx           shown at /dashboard
      settings/
        page.tsx         shown at /dashboard/settings
      default.tsx
TSX
// app/dashboard/layout.tsx (read-only)
export default function DashboardLayout({
  children,
  analytics,
  team,
}: {
  children: React.ReactNode;
  analytics: React.ReactNode;
  team: React.ReactNode;
}) {
  return (
    <div className="grid grid-cols-3 gap-4">
      <main className="col-span-2">{children}</main>
      <aside>
        {analytics}
        {team}
      </aside>
    </div>
  );
}

children is really just an implicit slot named @children, which is why app/dashboard/page.tsx and a hypothetical app/dashboard/@children/page.tsx mean the same thing. What the layout gets from the extra slots:

  • Independent loading and errors. Each slot can have its own loading.tsx and error.tsx. A slow chart streams in while the team list is already visible, and a crash in the chart does not blank the page. See loading.tsx, error.tsx and not-found.tsx and Streaming with Suspense.
  • Independent navigation. Each slot can have sub-pages (@team/settings/page.tsx) that change on their own.
  • Conditional rendering. The layout can pick a slot by condition, for example showing admin or member content depending on the user's role, while the URL stays the same.

Soft and hard navigation

The complication is that a URL names only one place, but a slot tree has several. Suppose the visitor is at /dashboard and clicks a link to /dashboard/settings. The @team slot has a page for that URL, so it changes. The @analytics slot has no settings folder. What should it show?

Next.js answers differently depending on how the navigation happened:

  • Soft navigation (a client-side transition, such as a Link click, router.push, or Back/Forward): Next.js knows what each slot was showing a moment ago, so a slot with no match keeps its previous page. The chart stays on screen while the rest changes.
  • Hard navigation (a full page load: a reload, the first visit, a link opened in a new tab): there is no previous state. Every slot must be derived from the URL alone, and a slot without a matching page has nothing to show.

For the hard case, Next.js looks for default.tsx in that slot. It is the fallback for "I have no page for this URL". If it is missing, the slot gives a 404. In Next.js 16 the build fails when a slot has no default.tsx, so write it from day one. In most cases it is one line:

TSX
// app/dashboard/@analytics/default.tsx (read-only)
export default function Default() {
  return null; // or a placeholder / the same component as page.tsx
}
flowchart TD
    A["Navigate to /dashboard/settings"] --> B{"Soft or hard?"}
    B -->|"Soft: click inside the app"| C["Slot has a matching page?"]
    C -->|"Yes"| D["Render that page"]
    C -->|"No"| E["Keep what the slot showed before"]
    B -->|"Hard: reload or shared link"| F["Slot has a matching page?"]
    F -->|"Yes"| D
    F -->|"No"| G["default.tsx exists?"]
    G -->|"Yes"| H["Render default.tsx"]
    G -->|"No"| I["404"]

The same URL can produce different slot contents depending on how the visitor arrived. default.tsx covers the hard path.

Try it. The stand-in below has a children slot, an @analytics slot that only has a page for /dashboard, and an @team slot with pages for both URLs. Navigate softly to the settings URL, then do a hard load of the same URL, then switch off default.tsx for @analytics and hard-load again.

Slots: soft vs hard navigation and default.tsx

After the soft move to /dashboard/settings, @analytics still shows the traffic chart, labeled as kept. After the hard load of the same URL, it falls back to default.tsx. Switch the file off and hard-load again: the slot reports a 404, and in a real project this is the situation that makes the build fail in version 16. Moving softly back to /dashboard gives the chart again, because it now has a matching page.

Intercepting routes

Now the second tool. Imagine app/photo/[id]/page.tsx is a full page for one photo. You would like clicking a thumbnail in the gallery to show that photo in a modal over the gallery, yet keep the URL /photo/2, so it can be shared and refreshed. An intercepting route says: "when someone navigates to this URL from inside the app, render this instead".

You name the folder with a prefix that says how many route levels up to look for the target:

Prefix Intercepts
(.)photo a route on the same level
(..)photo a route one level up
(..)(..)photo a route two levels up
(...)photo a route from the root app directory

Careful: the levels count route segments, not folders on disk. Slots (@modal) and route groups ((shop)) do not count as levels, because they are not part of the URL. That is why the usual modal setup uses (.), even though the file sits one folder deeper than the page it replaces:

TEXT
app/
  layout.tsx             receives children and modal
  page.tsx               the gallery
  photo/
    [id]/
      page.tsx           the FULL page: /photo/2 on a hard load
  @modal/
    default.tsx          returns null: no modal when nothing is intercepted
    (.)photo/
      [id]/
        page.tsx         the MODAL: /photo/2 on a soft navigation
TSX
// app/layout.tsx (read-only)
export default function RootLayout({
  children,
  modal,
}: {
  children: React.ReactNode;
  modal: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        {children}
        {modal}
      </body>
    </html>
  );
}
TSX
// app/@modal/(.)photo/[id]/page.tsx (read-only)
'use client';

import { useRouter } from 'next/navigation';
import { use } from 'react';

export default function PhotoModal({ params }: { params: Promise<{ id: string }> }) {
  const { id } = use(params);
  const router = useRouter();

  return (
    <div role="dialog" aria-modal="true" aria-label={`Photo ${id}`}>
      <p>Photo {id}</p>
      <button onClick={() => router.back()}>Close</button>
    </div>
  );
}

How it plays out:

  1. The visitor is on / and clicks <Link href="/photo/2">. This is a soft navigation, so the router checks for interception. It finds @modal/(.)photo/[id], renders it in the modal slot, and leaves children (the gallery) alone, which is why the gallery stays visible behind the dialog.
  2. The URL in the address bar is now /photo/2. Close the modal with router.back(): the history entry for / is restored and the modal slot returns to default.tsx (nothing).
  3. If the visitor reloads at /photo/2, or opens the link in a new tab, or a crawler fetches it, that is a hard navigation. Interception is skipped, so the real app/photo/[id]/page.tsx renders as a normal page.

Every modal route therefore needs two pages: the modal and the full page. They often share one component and differ only in the wrapper.

There is one trap. A slot keeps its previous state on soft navigation, so a visitor who clicks a header link while the modal is open could find the modal still floating there. To close it for any other navigation, add a catch-all page to the slot that renders nothing: app/@modal/[...catchAll]/page.tsx returning null. Back and Forward do not need it, because they restore the saved state of each history entry.

The stand-in below implements exactly this. It has a history list, so Back works like the real thing. Click a photo, then press Back; click a photo and then About (with and without the catch-all); finally click a photo and press "Reload (hard load)".

A photo modal with an intercepting route

Click "Lagoon": the URL line shows /photo/2, the gallery stays, and the modal appears. Press Back and both the URL and the modal go away. Click "Lagoon" again and then "About" with the catch-all missing: the page changes to About, but the modal is still there, because the @modal slot had no match and kept its state. Switch the catch-all on and repeat: the modal disappears. Finally, open a photo and press "Reload (hard load)": the dialog is replaced by the full page for the same URL.

When to use what

  • Several independent regions on one page (dashboards, feeds with a side panel): parallel routes, with a default.tsx in every slot.
  • Role- or state-dependent areas (admin versus member views): parallel routes plus a condition in the layout.
  • A modal, drawer or quick preview with its own shareable URL (photo viewers, login dialogs, product quick-view): an intercepting route inside a @modal slot, plus the full page.
  • A modal with no URL need: plain client state. Not everything has to be a route.

Remember accessibility: a modal route still needs a dialog role, focus management and Escape-to-close, and the full page must be a complete page in its own right, because that is what search engines and shared links see. The same URL-driven idea in React Router is covered in React Router Modal Routes.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Where does the content of app/dashboard/@analytics/page.tsx appear?

    A folder starting with @ is a slot, not a URL segment. Its page is passed to the layout one level above as a prop with the slot's name.
  2. 2. A visitor reloads /dashboard/settings. The @analytics slot has no settings page. What decides what that slot shows?

    A reload is a hard navigation, so no previous state exists. An unmatched slot falls back to default.tsx, and without one it renders a 404 (a build error in Next.js 16).
  3. 3. Why is the modal folder written as @modal/(.)photo/[id] instead of @modal/(..)photo/[id]?

    Interception prefixes count URL segments. A slot (and a route group) adds none, so the intercepting folder is on the same route level as photo/[id].
  4. 4. A shared link to /photo/2 is opened in a new tab. What renders?

    Opening a link fresh is a hard navigation. The interception is skipped and the real route renders, which is why every modal route needs a full page too.
  5. 5. The modal stays visible after clicking a regular header link. What is the usual fix?

    A slot with no match keeps its previous state on soft navigation. A catch-all page that renders null matches every other URL and closes the modal.

Summary

  • A folder named @slot is a parallel route: it adds no URL segment and arrives as a prop of the parent layout, with its own loading and error handling.
  • Soft navigation keeps the previous page of slots that do not match the new URL; hard navigation (reload, new tab, shared link) cannot, so unmatched slots render default.tsx, or a 404 without it. Next.js 16 requires default.tsx in every slot.
  • Intercepting routes use (.), (..), (..)(..) and (...), counted in route segments (slots and groups do not count), to show a different page on soft navigation.
  • The modal recipe is @modal/(.)photo/[id] plus @modal/default.tsx returning null plus the full page photo/[id]/page.tsx.
  • Close with router.back(), and add @modal/[...catchAll]/page.tsx returning null so other navigations close the modal.
  • Treat the modal as a real dialog (role, focus, Escape) and the full page as a real page.

Next: loading.tsx, error.tsx and not-found.tsx