typescriptadvanced
Intercepting Routes Modal
Show content in a modal on soft navigation while preserving the full page on hard navigation.
typescriptPress ⌘/Ctrl + Shift + C to copy
// app/@modal/(.)photo/[id]/page.tsx
// The (.) prefix intercepts /photo/[id] at the same level
import { Modal } from '@/components/Modal';
export default function PhotoModal({ params }: { params: { id: string } }) {
return (
<Modal>
<img
src={`/photos/${params.id}.jpg`}
alt={`Photo ${params.id}`}
className="max-h-[80vh] rounded-xl"
/>
</Modal>
);
}
// app/@modal/default.tsx
export default function Default() {
return null; // No modal by default
}
// app/layout.tsx
export default function Layout({
children,
modal,
}: {
children: React.ReactNode;
modal: React.ReactNode;
}) {
return (
<>
{children}
{modal}
</>
);
}Use Cases
- Photo gallery modals
- Login interceptors
- Quick preview overlays
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
typescriptadvanced
Parallel Routes Layout
Next.js parallel routes pattern to render multiple page slots simultaneously in a shared layout.
Best for: Dashboard multi-panel layouts
#parallel-routes#layout
typescriptadvanced
Next.js Parallel Routes Layout
Use parallel routes with named slots to render multiple pages simultaneously in a layout.
Best for: Dashboard layouts with independent loading states
#nextjs#routing
typescriptadvanced
Next.js Intercepting Routes for Modals
Implement modal patterns with intercepting routes that work with both soft and hard navigation.
Best for: Image gallery modals with shareable URLs
#nextjs#routing
typescriptadvanced
Parallel Routes for Modal Pattern
Implement modal dialogs using parallel routes and route interception for shareable modal URLs.
Best for: photo galleries
#nextjs#parallel-routes