Intercepted route modal
What you need to know
Intercepting routes let client navigation display a destination inside a different layout context while preserving a direct URL to the destination. A bookstore can show a book preview over a catalog, while a shared link or refresh opens the ordinary detail page. Combining an interception with a parallel slot makes this pattern possible.
By the end, you can: compare hard and soft navigation; design focus restoration.
Intercepted detail route tree
app/ layout.tsx page.tsx catalog/page.tsx book/[slug]/page.tsx @preview/ default.tsx page.tsx (.)book/[slug]/page.tsx [...rest]/page.tsxExpected behavior (not framework-tested): A client Link from /catalog to /book/moss may display the intercepted detail in the preview slot. Opening /book/moss directly renders the regular detail page; the default preview is empty.
How it works
Interception notation uses route segments, not the physical count of folders: (.) selects the same level, (..) one segment above, (..)(..) two above and (...) the app root. A named slot is not counted as a segment. The root layout must render the preview prop. Provide an explicit null default and empty matching routes for navigation away, so a previously active slot does not remain visible unintentionally. The normal route must work independently on reload.
app/@preview/(.)book/[slug]/page.tsx (requires PreviewDialog client wrapper)
import { notFound } from "next/navigation";import PreviewDialog from "../../../PreviewDialog";const titles = new Map([["moss", "Moss Garden"], ["fern", "Fern Field"]]);export default async function Preview({ params }: { params: Promise<{ slug: string }> }) { const title = titles.get((await params).slug); if (!title) notFound(); return <PreviewDialog title={title}><p>Read the full description on the detail page.</p></PreviewDialog>;}Expected behavior (not framework-tested): The wrapper, provided in the staged fixture, opens a native dialog and uses router.back for the known intercepted history path. A direct URL uses the normal page instead.
Common mistake
A visible overlay is not automatically an accessible modal. Provide an accessible name, focus on open, keyboard dismissal, a visible close button, focus restoration when the opener remains, and a tested fallback focus target if it disappears. Do not use router.back blindly from arbitrary direct visits.
Practice and verification
Use the staged fixture to test catalog link, Escape, close, back/forward, direct URL and refresh. Check focus returns to the opener or a logical visible fallback; test missing slugs as a separate outcome.
Scope: App Router, proposed Next.js 16.x, Cache Components disabled for these labs. Snippets assume a reviewed TypeScript app and are static examples; framework behavior has not been executed. Exact supported patch and dependency set must be verified before running.