Good Code
The good version uses the layout for persistent navigation and places route-specific content in the child page.
Lesson 02
Keep shared chrome in layouts and route-specific data in pages.
import Link from "next/link";
export default function DashboardLayout({
children,
}: {
children: React.ReactNode;
}) {
// The layout owns shared navigation while child pages supply route content.
return (
<section>
<nav aria-label="Dashboard">
<Link href="/dashboard">Overview</Link>
<Link href="/dashboard/reviews">Reviews</Link>
</nav>
<main>{children}</main>
</section>
);
}import { getLatestReviews } from "@/lib/reviews";
export default async function DashboardLayout({
children,
}: {
children: React.ReactNode;
}) {
// Fetching leaf-page data here blocks child routes that may not need it.
const reviews = await getLatestReviews();
return (
<section>
<aside>{reviews.length} reviews need attention</aside>
<main>{children}</main>
</section>
);
}The good version uses the layout for persistent navigation and places route-specific content in the child page.
The bad version fetches leaf-page data inside the layout, so every child route can be blocked by data it may not need.