What are intercepting routes?

Intercepting routes load a different route inside the current layout during client-side navigation, while a direct visit or refresh shows the route's normal page. The classic use is a photo feed where clicking a photo opens it in a modal but sharing the URL opens the full photo page.

Conventions

The folder prefix says where the intercepted route lives, relative to route segments (not the file system):

  • (.)photo matches a segment at the same level.
  • (..)photo matches one level up.
  • (..)(..)photo matches two levels up.
  • (...)photo matches from the root app directory.

Slots (@modal) and route groups do not count as segments when computing levels.

Modal pattern

  1. Create a parallel route slot app/@modal and render {modal} in the root layout.
  2. Add app/@modal/(.)photos/[id]/page.tsx that renders the photo inside a modal.
  3. Keep the real page at app/photos/[id]/page.tsx.
  4. Add app/@modal/default.tsx returning null so the slot is empty when no modal is open.
  5. Close with router.back().

What users get

  • Clicking a link from the feed opens the modal, keeping the feed and its scroll position underneath.
  • The URL changes to /photos/123, so it can be shared.
  • Refreshing or opening the link directly shows the full page.
  • Back closes the modal; Forward reopens it.

Pitfalls

  • Interception only happens on soft navigation (<Link>, router.push).
  • Missing default.tsx in the slot breaks the build in Next.js 16.
  • To close the modal when navigating elsewhere, add a catch-all @modal/[...catchAll]/page.tsx returning null.

Code example

tsx
1// app/layout.tsx
2export default function RootLayout({ children, modal }: LayoutProps<"/">) {
3 return (
4 <html lang="en">
5 <body>
6 {children}
7 {modal}
8 </body>
9 </html>
10 );
11}
12
13// app/@modal/default.tsx
14// export default function Default() { return null; }
15
16// app/@modal/(.)photos/[id]/page.tsx - shown on soft navigation
17import { Modal } from "@/components/modal"; // "use client", calls router.back() on close
18
19export default async function PhotoModal({ params }: PageProps<"/photos/[id]">) {
20 const { id } = await params;
21 return (
22 <Modal>
23 <img src={`/photos/${id}.jpg`} alt={`Photo ${id}`} />
24 </Modal>
25 );
26}
27
28// app/photos/[id]/page.tsx - shown on direct visit or refresh
29// export default async function PhotoPage({ params }) { ...full page... }

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app