A page reads searchParams, one has generateStaticParams, and two wait for connection(). What does the route table print?
The tea shop has a home page, a tea list that can be sorted with ?sort=price, a page for each of its four teas, a stock page with a loading.tsx, and a stock API. Cache Components is on, as create-next-app sets it up. Which symbol does next build print for each route, and which tea pages does it list?
app/layout.tsximport Link from "next/link";
export const metadata = { title: "Leaf and Kettle" };
export default function RootLayout({ children }: LayoutProps<"/">) {
return (
<html lang="en">
<body>
<nav>
<Link href="/">Home</Link> <Link href="/teas">Teas</Link>
</nav>
{children}
</body>
</html>
);
}
lib/teas.tsexport type Tea = { slug: string; name: string; price: number };
export const teas: Tea[] = [
{ slug: "green", name: "Green tea", price: 4 },
{ slug: "mint", name: "Mint tea", price: 3 },
{ slug: "oolong", name: "Oolong tea", price: 6 },
{ slug: "jasmine", name: "Jasmine tea", price: 5 },
];
export function getTea(slug: string) {
return teas.find((tea) => tea.slug === slug);
}
app/page.tsxexport default function Home() {
return (
<main>
<h1>Leaf and Kettle</h1>
<p>Loose-leaf tea, packed by hand.</p>
</main>
);
}
app/teas/page.tsximport { Suspense } from "react";
import Link from "next/link";
import { teas } from "@/lib/teas";
async function TeaList({ searchParams }: { searchParams: PageProps<"/teas">["searchParams"] }) {
const { sort } = await searchParams;
const shown = sort === "price" ? [...teas].sort((a, b) => a.price - b.price) : teas;
return (
<ul>
{shown.map((tea) => (
<li key={tea.slug}>
<Link href={`/teas/${tea.slug}`}>{tea.name}</Link>: ${tea.price}
</li>
))}
</ul>
);
}
export default function TeasPage({ searchParams }: PageProps<"/teas">) {
return (
<main>
<h1>Our teas</h1>
<Suspense fallback={<p>Sorting the teas…</p>}>
<TeaList searchParams={searchParams} />
</Suspense>
</main>
);
}
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.price} a box</p>
</main>
);
}
app/stock/page.tsximport { connection } from "next/server";
import { teas } from "@/lib/teas";
export default async function StockPage() {
await connection();
const time = new Date().toISOString().slice(11, 16);
return (
<main>
<h1>Stock</h1>
<p>
{teas.length} teas counted at {time} UTC.
</p>
</main>
);
}
app/stock/loading.tsxexport default function Loading() {
return <p>Counting the tins…</p>;
}
app/api/stock/route.tsimport { connection } from "next/server";
import { teas } from "@/lib/teas";
export async function GET() {
await connection();
return Response.json({ teas: teas.length, countedAt: new Date().toISOString() });
}
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. What happens:
- You run
next build.
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…