completefrontend

Predict the outputHard

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.tsx
import 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.ts
export 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.tsx
import { 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:

  1. You run next build, then next start.
  2. You ask the server for /teas/mint.
  3. 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…