typescriptadvanced
Next.js Parallel Routes Layout
Use parallel routes with named slots to render multiple pages simultaneously in a layout.
typescriptPress ⌘/Ctrl + Shift + C to copy
// app/dashboard/layout.tsx
export default function DashboardLayout({
children,
analytics,
notifications,
}: {
children: React.ReactNode;
analytics: React.ReactNode;
notifications: React.ReactNode;
}) {
return (
<div className="grid grid-cols-12 gap-4">
<main className="col-span-8">{children}</main>
<aside className="col-span-4 space-y-4">
{analytics}
{notifications}
</aside>
</div>
);
}
// app/dashboard/@analytics/page.tsx
export default async function AnalyticsSlot() {
const data = await fetch('https://api.example.com/analytics');
const stats = await data.json();
return (
<div className="rounded-xl border p-4">
<h2>Analytics</h2>
<p>Visitors: {stats.visitors}</p>
</div>
);
}
// app/dashboard/@notifications/page.tsx
export default async function NotificationsSlot() {
const res = await fetch('https://api.example.com/notifications');
const items = await res.json();
return (
<ul>
{items.map((n: { id: string; text: string }) => (
<li key={n.id}>{n.text}</li>
))}
</ul>
);
}
// app/dashboard/@analytics/default.tsx (fallback)
export default function Default() {
return null;
}Use Cases
- Dashboard layouts with independent loading states
- Rendering multiple views in a single page
- Conditional slot rendering based on auth state
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
typescriptintermediate
Route Groups for Layout Organization
Use route groups to share layouts across routes without affecting URL structure.
Best for: Marketing vs. dashboard layouts
#nextjs#routing
typescriptadvanced
Intercepting Routes Modal
Show content in a modal on soft navigation while preserving the full page on hard navigation.
Best for: Photo gallery modals
#routing#modals
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