Parallel routes @slot rendering, default.js and the unmatched slot 404 trap, template.js vs layout.js state semantics, intercepting route modal patterns, soft vs hard navigation mechanics, and route group layout inheritance.
A-7 — Advanced Routing Internals: Parallel, Intercepting, Templates
Who this is for: Architects who hit the wall with basic App Router layouts and need to understand the features designed for complex UI patterns — the ones that make Twitter-style photo modals, side-by-side dashboards, and multi-step checkout flows possible without reaching for a client-side routing library.
Why the App Router's Layout Model Isn't Enough on Its Own
The default App Router layout model is a single slot: each route renders one page component inside its nearest layout. This is correct for most applications. But a category of UI patterns requires more:
- Photo modal on scroll: User clicks a photo in a grid. A modal opens with the photo fullscreen. The URL changes to
/photos/123. If the user refreshes, they get the standalone photo page, not the modal. The underlying grid remains visible and scrolled to the right position behind the modal. - Dashboard with independent panels: An analytics dashboard where the left sidebar shows a team list and the right panel shows the selected team's metrics. Each panel can be navigated independently without re-rendering the other.
- Wizard with back navigation: A checkout flow where the browser back button navigates between steps in the wizard, and the URL reflects the current step.
Parallel routes and intercepting routes are the App Router's answer to these patterns. They're not workarounds — they're first-class routing primitives.
Parallel Routes — Multiple Slots in One Layout
Parallel routes let a single layout render multiple independent pages simultaneously. Each slot is a named directory prefixed with @:
Each slot receives its own independent Server Component subtree. When the user navigates within one slot (e.g., /dashboard/analytics/weekly), only that slot re-renders. The other slots are unaffected — their Server Component trees don't re-execute.
The default.tsx requirement: When a slot has sub-routes (e.g., @analytics/weekly/page.tsx), it needs a default.tsx at the slot root. This is shown when the URL doesn't match any sub-route of that slot. Without it, navigating to a URL that matches the main page.tsx but has no corresponding sub-route for a slot causes a 404.
Intercepting Routes — The Modal Pattern
Intercepting routes let you "intercept" a navigation that would normally go to a full page, and instead render the destination inside a modal on top of the current page.
The convention uses (.) to indicate the interception level:
The (.) in (.)photos/[id] means "intercept the route at the same level." The interception levels:
(.)— same level(..)— one level up(..)(..)— two levels up(...)— root level
Sign in to keep reading
The rest of this module is free — sign in with Google to unlock it and track your progress.
Sign in & RegisterDiscussion
0Join the discussion