layout.tsx that accepts a children prop.1export default function DashboardLayout({2children,3}: {4children: React.ReactNode;5}) {6return (7<div className="dashboard">8{/* Persistent sidebar */}9// !mark10<Sidebar />11{/* Child routes render here */}12// !mark13<main>{children}</main>14</div>15);16}
Layouts preserve state and remain interactive across navigation.
| Topic | Guidance |
|---|---|
| Re-renders on navigation | No — layouts stay mounted |
| Client state | Preserved across child route changes |
| Interactivity | Remains interactive during page loads |
| Best for | Headers, sidebars, navigation, persistent UI |
template.tsx file convention when you need UI that re-mounts on navigation.| Demo | Description |
|---|---|
| Loading | Add loading states to layouts |
| Error | Handle errors within layout boundaries |
| Route Groups | Organize routes without affecting URLs |
| Template | Re-mount UI on navigation |








