With generateStaticParams and notFound() in a dynamic route, what do /teas/mint and /teas/rooibos answer?
The tea shop has one page for every tea, app/teas/[slug]/page.tsx. It lists the shop's three teas in generateStaticParams, and calls notFound() when the slug isn't one of them. Cache Components is on, as create-next-app sets it up. Say each response's status, and what its HTML shows before any JavaScript runs.
app/layout.tsximport Link from "next/link";
export const metadata = { title: "Leaf and Kettle" };
export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
return (
<html lang="en">
<body>
<nav>
<Link href="/teas/green">Green tea</Link> <Link href="/teas/mint">Mint tea</Link>
</nav>
{children}
</body>
</html>
);
}
lib/teas.tsexport type Tea = { slug: string; name: string; about: string };
export const teas: Tea[] = [
{ slug: "green", name: "Green tea", about: "Light and fresh." },
{ slug: "mint", name: "Mint tea", about: "Cool and sweet." },
{ slug: "oolong", name: "Oolong tea", about: "Rich and smooth." },
];
export function getTea(slug: string) {
return teas.find((tea) => tea.slug === slug);
}
app/teas/[slug]/page.tsximport { notFound } from "next/navigation";
import { getTea, teas } from "@/lib/teas";
export function generateStaticParams() {
return teas.map((tea) => ({ slug: tea.slug }));
}
export default async function TeaPage({ params }: PageProps<"/teas/[slug]">) {
const { slug } = await params;
const tea = 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 build, thennext start. - You ask the server for
/teas/mint. - Then you ask it for
/teas/rooibos, a tea the shop doesn't sell.
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…