The root layout has a title template and the teas section has a layout with a plain title. What title does each page get?
Leaf and Kettle wants every tab to end with | Leaf and Kettle, so the root layout sets a title template. The home page and the about page set titles of their own, the teas section's layout sets Our teas, the tea list sets none, and each tea's page sets the tea's name in generateMetadata. What's in each page's <title>?
lib/teas.tsexport type Tea = { slug: string; name: string; about: string };
const teas: Tea[] = [
{ slug: "green", name: "Green tea", about: "Light and fresh." },
{ slug: "mint", name: "Mint tea", about: "Cool and sweet." },
];
/** Every tea the shop sells, in the shop's order. */
export async function getTeas(): Promise<Tea[]> {
return teas;
}
/** The tea with this slug, or undefined when the shop doesn't sell it. */
export async function getTea(slug: string): Promise<Tea | undefined> {
return teas.find((tea) => tea.slug === slug);
}
app/layout.tsximport type { Metadata } from "next";
export const metadata: Metadata = {
title: {
template: "%s | Leaf and Kettle",
default: "Leaf and Kettle",
},
};
export default function RootLayout({ children }: LayoutProps<"/">) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
app/page.tsximport type { Metadata } from "next";
export const metadata: Metadata = { title: "Home" };
export default function HomePage() {
return <h1>Welcome to Leaf and Kettle</h1>;
}
app/about/page.tsximport type { Metadata } from "next";
export const metadata: Metadata = { title: "About us" };
export default function AboutPage() {
return <h1>About us</h1>;
}
app/teas/layout.tsximport type { Metadata } from "next";
export const metadata: Metadata = { title: "Our teas" };
export default function TeasLayout({ children }: LayoutProps<"/teas">) {
return (
<section>
<p>Loose-leaf teas, packed by hand.</p>
{children}
</section>
);
}
app/teas/page.tsximport Link from "next/link";
import { getTeas } from "@/lib/teas";
export default async function TeasPage() {
const teas = await getTeas();
return (
<ul>
{teas.map((tea) => (
<li key={tea.slug}>
<Link href={`/teas/${tea.slug}`}>{tea.name}</Link>
</li>
))}
</ul>
);
}
app/teas/[slug]/page.tsximport type { Metadata } from "next";
import { notFound } from "next/navigation";
import { getTea, getTeas } from "@/lib/teas";
export async function generateStaticParams() {
const teas = await getTeas();
return teas.map((tea) => ({ slug: tea.slug }));
}
export async function generateMetadata({ params }: PageProps<"/teas/[slug]">): Promise<Metadata> {
const { slug } = await params;
const tea = await getTea(slug);
if (!tea) notFound();
return { title: tea.name };
}
export default async function TeaPage({ params }: PageProps<"/teas/[slug]">) {
const { slug } = await params;
const tea = await getTea(slug);
if (!tea) notFound();
return (
<main>
<h1>{tea.name}</h1>
<p>{tea.about}</p>
</main>
);
}
It's a project create-next-app made (Next.js 16.4.3, TypeScript, the App Router, and Cache Components on) with these files, built with next build and run with next start. What happens:
- You run
next buildand start the app withnext start. - You open
/,/about,/teas, and/teas/mint.
The answer
Work out what Next.js does at each step: what the build prints, what each request answers, and what the page shows. Then check.
Checking your sign-in…