In any layout.tsx in Next.js, we put the common layout elements such as headers, footers, sidebars and this also loads children which renders page.tsx.
The following code snippet is picked from shadcn-ui/ui:
import { Metadata } from "next"import Link from "next/link"import { cn } from "@/lib/utils"import { Announcement } from "@/components/announcement"import { ExamplesNav } from "@/components/examples-nav"import { PageActions, PageHeader, PageHeaderDescription, PageHeaderHeading,} from "@/components/page-header"import { buttonVariants } from "@/registry/new-york/ui/button"export const metadata: Metadata = { title: "Examples", description: "Check out some examples app built using the components.",}interface ExamplesLayoutProps { children: React.ReactNode}export default function ExamplesLayout({ children }: ExamplesLayoutProps) { return ( <div className="container relative"> <PageHeader> <Announcement /> <PageHeaderHeading className="hidden md:block"> Check out some examples </PageHeaderHeading> <PageHeaderHeading className="md:hidden">Examples</PageHeaderHeading> <PageHeaderDescription> Dashboard, cards, authentication. Some examples built using the components. Use this as a guide to build your own. </PageHeaderDescription> <PageActions> <Link href="/docs" className={cn(buttonVariants(), "rounded-[6px]")}> Get Started </Link> <Link href="/components" className={cn( buttonVariants({ variant: "outline" }), "rounded-[6px]" )} > Components </Link> </PageActions> </PageHeader> <section> <ExamplesNav /> <div className="overflow-hidden rounded-[0.5rem] border bg-background shadow"> {children} </div> </section> </div> )}
It has the PageHeader , ExamplesNav , children
children renders the sub routes with in the examples folder.
This is how you are able to see the Mail example with out any change in the URL when you visit ui.shadcn.com, it just directly loads MailPage component. Interesting.
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.