Build modals, split views, and soft navigation using Next.js parallel and intercepting routes with @slot patterns and (.) segment conventions. This practical guide covers step-by-step setup, real-world code snippets, security hardening, and common production edge cases.
Introduction
Two of the most powerful — and most misunderstood — features of the Next.js App Router are parallel routes and intercepting routes. Together they let you build complex UI patterns like modals that preserve browser history, split-screen dashboards, and conditional layouts — all within the file-system routing convention.
In this guide you'll learn exactly what both features do, when to use each, and how to build the classic photo gallery with modal pattern.
Prerequisites
- Next.js 14 or 15 with the App Router
- Understanding of
layout.tsxandpage.tsxconventions - Familiarity with React Server and Client Components
1. What Are Parallel Routes?
Parallel routes let you render multiple pages simultaneously inside a single layout. Instead of one {children} slot, your layout receives multiple named slots — each resolving to its own page.tsx.
The @slot convention
Create a folder prefixed with @ to define a named slot:
app/
layout.tsx ← receives @feed and @modal slots
page.tsx ← renders at /
@feed/
page.tsx ← default feed content
@modal/
default.tsx ← rendered when no modal is active (null/empty)
page.tsx ← optional — rarely used at root
Your layout accepts the slots as props:
// app/layout.tsx
export default function RootLayout({
children,
feed,
modal,
}: {
children: React.ReactNode;
feed: React.ReactNode;
modal: React.ReactNode;
}) {
return (
<html lang="en">
<body>
{children}
{feed}
{modal}
</body>
</html>
);
}
The default.tsx fallback
When a slot has no matching page for the current URL, Next.js renders default.tsx instead. Without it, you get a 404 for that slot.
// app/@modal/default.tsx
export default function ModalDefault() {
return null; // render nothing when no modal is open
}
2. Parallel Route Use Cases
Dashboard with independent panels
app/
dashboard/
layout.tsx ← has @analytics and @activity slots
page.tsx
@analytics/
page.tsx ← /dashboard — analytics panel
@activity/
page.tsx ← /dashboard — activity panel
default.tsx
Both panels load independently — if @analytics is slow, it doesn't block @activity from rendering.
Conditional rendering based on auth
// app/layout.tsx
import { getServerSession } from 'next-auth';
export default async function Layout({
children,
dashboard,
login,
}: {
children: React.ReactNode;
dashboard: React.ReactNode;
login: React.ReactNode;
}) {
const session = await getServerSession();
return <>{session ? dashboard : login}</>;
}
3. What Are Intercepting Routes?
Intercepting routes let you render a route within the current layout context when navigating client-side — while showing the full page on hard navigation (direct URL, refresh).
The classic example: a photo feed where clicking a photo opens it in a modal (soft nav), but opening the photo URL directly shows the full photo page (hard nav).
The (.) prefixes
| Prefix | Intercepts from |
|---|---|
(.)segment | Same level |
(..)segment | One level up |
(..)(..)segment | Two levels up |
(...)segment | Root |
4. Building a Photo Gallery Modal
File structure
app/
layout.tsx
page.tsx ← photo feed
@modal/
default.tsx ← null (no modal)
(.)photos/
[id]/
page.tsx ← modal version
photos/
[id]/
page.tsx ← full photo page (hard nav)
Step 1 — The root layout with the modal slot
// app/layout.tsx
export default function Layout({
children,
modal,
}: {
children: React.ReactNode;
modal: React.ReactNode;
}) {
return (
<html lang="en">
<body>
{modal}
{children}
</body>
</html>
);
}
Step 2 — The feed page
// app/page.tsx
import Link from 'next/link';
const photos = [
{ id: '1', src: 'https://picsum.photos/id/1/600/400', title: 'Forest' },
{ id: '2', src: 'https://picsum.photos/id/2/600/400', title: 'Laptop' },
{ id: '3', src: 'https://picsum.photos/id/3/600/400', title: 'Coffee' },
];
export default function FeedPage() {
return (
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 16, padding: 24 }}>
{photos.map((photo) => (
<Link key={photo.id} href={`/photos/${photo.id}`}>
<img src={photo.src} alt={photo.title} style={{ width: '100%', borderRadius: 8 }} />
</Link>
))}
</div>
);
}
Step 3 — The intercepting modal version
// app/@modal/(.)photos/[id]/page.tsx
'use client';
import { useRouter } from 'next/navigation';
export default function PhotoModal({ params }: { params: { id: string } }) {
const router = useRouter();
return (
<div
onClick={() => router.back()}
style={{
position: 'fixed', inset: 0,
background: 'rgba(0,0,0,0.85)',
display: 'flex', alignItems: 'center', justifyContent: 'center',
zIndex: 100,
}}
>
<div onClick={(e) => e.stopPropagation()}>
<img
src={`https://picsum.photos/id/${params.id}/800/600`}
alt="Photo"
style={{ borderRadius: 12, maxWidth: '90vw', maxHeight: '80vh' }}
/>
<button
onClick={() => router.back()}
style={{ position: 'absolute', top: 16, right: 16, color: '#fff', fontSize: 24 }}
>
✕
</button>
</div>
</div>
);
}
Step 4 — The full photo page (hard navigation)
// app/photos/[id]/page.tsx
export default function PhotoPage({ params }: { params: { id: string } }) {
return (
<div style={{ padding: 40 }}>
<img
src={`https://picsum.photos/id/${params.id}/1200/800`}
alt="Full photo"
style={{ width: '100%', borderRadius: 12 }}
/>
</div>
);
}
Step 5 — The modal default (nothing)
// app/@modal/default.tsx
export default function ModalDefault() {
return null;
}
Result: Clicking a photo from the feed opens it in a modal (client-side). Refreshing or sharing the URL /photos/1 shows the full page — no modal.
5. Soft vs Hard Navigation
| Navigation type | What renders |
|---|---|
Client-side <Link> click | Intercepting route (modal) |
| Full URL visit / page refresh | Regular route (full page) |
router.back() | Dismisses the intercepting route |
This is the magic: intercepting routes don't change the canonical page — they just layer over it during client navigation.
6. Combining Parallel + Intercepting Routes
A common pattern in production apps:
app/
layout.tsx ← has @modal slot
@modal/
default.tsx ← null
(.)items/[id]/
page.tsx ← item detail modal
items/
page.tsx ← items list
[id]/
page.tsx ← full item detail page
Your items list links to /items/123. Client-side: modal opens over the list. Hard refresh on /items/123: full detail page shows.
7. Common Mistakes
Missing default.tsx
Without default.tsx in a slot, any navigation where the slot has no matching route throws a 404.
Forgetting 'use client' on the modal
The router.back() call and onClick handlers require a Client Component.
Wrong intercept prefix
If your intercepting route is at app/@modal/(.)photos/[id], the (.) intercepts /photos/[id] at the same level as app/. If your photos route is nested deeper, use (..) accordingly.
Conclusion
Parallel and intercepting routes solve a hard problem in React apps: how to show contextual UI (like modals) that:
- Preserves the URL
- Supports browser back/forward
- Shows a full page on direct access
- Doesn't require client-side state hacks
The key patterns to remember:
@slotfolders create named slots in layoutsdefault.tsxprevents 404s when a slot has no active page(.),(..),(...)prefixes control which route gets intercepted- Intercepting routes only activate on client-side navigation — hard refreshes bypass them
These features are particularly powerful when building admin dashboards, social feeds, e-commerce product grids, and any UI where context-preserving overlays improve UX.
Written by Dev Pattern LabsCore Engineering
Dev Pattern Labs is an engineering lab and digital consultancy specializing in custom Next.js web applications, WooCommerce REST API integrations, and workflow automation for growing businesses.
Recommended Companion Articles

Dynamic Open Graph Image Generation with Next.js 15 and @vercel/og
Generate dynamic, high-converting Open Graph social preview cards in Next.js 15 using Satori and Edge Runtime. Boost social CTR and SEO indexation.

Next.js 15 Internationalization: App Router Multi-Language Guide
Configure multi-language localization in Next.js 15 App Router. Implement subpath routing, language middleware, translated metadata, and hreflang tags.

Next.js 15 and Supabase RLS: Complete Multi-Tenant Security Guide
Implement Postgres Row Level Security (RLS) in Next.js 15 and Supabase. Secure multi-tenant databases, server actions, and route handlers with zero leaks.
