Leaf and Kettle's brewing guides nest as deep as a topic needs: /guides/green, /guides/green/brewing, /guides/green/brewing/cold. Write one page for all of them, app/guides/[...slug]/page.tsx. The three dots make [...slug] a catch-all segment: it matches one or more segments after /guides, and Next.js passes them in params, a promise of { slug }, where slug is an array, ["green", "brewing"] for /guides/green/brewing. The bare /guides has a page of its own, so this one always gets at least one segment.
A guide's path is its segments joined with /, like green/brewing. Load it with getGuide(path) from @/lib/guides, and call notFound() from next/navigation when there's no guide at that path.
Show the guide's title in an <h1> and its body in a paragraph. Above them, put a breadcrumb trail: a <nav aria-label="Breadcrumb"> holding an <ol>, with an <li> for each step. First a Guides link to /guides, then a link to every guide above this one with its title as the text, and last the guide's own title as plain text, not a link. Make the links with next/link.
Also export generateStaticParams, which returns { slug } for every guide getGuides() gives, in order, with slug as the array of segments, so next build makes every guide's page ahead of time.
// /guides/green/brewing/cold has this trail:
<nav aria-label="Breadcrumb">
<ol>
<li><a href="/guides">Guides</a></li>
<li><a href="/guides/green">Green tea</a></li>
<li><a href="/guides/green/brewing">Brewing green tea</a></li>
<li>Cold brewing green tea</li>
</ol>
</nav>
// /guides/green/steeping → 404
lib/guides.ts, read-only. Import it as @/lib/guides.
export type Guide = { path: string; title: string; body: string };
const guides: Guide[] = [
{ path: "green", title: "Green tea", body: "Delicate leaves that like water below boiling." },
{ path: "green/brewing", title: "Brewing green tea", body: "Steep at 80°C for 2 minutes." },
{ path: "green/brewing/cold", title: "Cold brewing green tea", body: "Steep in cold water in the fridge for 6 hours." },
{ path: "oolong", title: "Oolong tea", body: "Rich, floral, and good for many short steeps." },
{ path: "oolong/brewing", title: "Brewing oolong tea", body: "Steep at 90°C for 1 minute, then a little longer each time." },
];
/** Every guide, in the shop's order. */
export async function getGuides(): Promise<Guide[]> {
return guides;
}
/** The guide at this path, like "green/brewing", or undefined when there's none. */
export async function getGuide(path: string): Promise<Guide | undefined> {
return guides.find((guide) => guide.path === path);
}
await renderServer(<Page params={params({ slug: ["green", "brewing"] })} />);
expect(screen.getByRole("heading", { level: 1, name: "Brewing green tea" })).toBeInTheDocument();
expect(screen.getByText("Steep at 80°C for 2 minutes.")).toBeInTheDocument();
await renderServer(<Page params={params({ slug: ["oolong"] })} />);
expect(screen.getByRole("heading", { level: 1, name: "Oolong tea" })).toBeInTheDocument();
cleanup();
await renderServer(<Page params={params({ slug: ["green", "brewing", "cold"] })} />);
expect(screen.getByRole("heading", { level: 1, name: "Cold brewing green tea" })).toBeInTheDocument();
expect(screen.getByText("Steep in cold water in the fridge for 6 hours.")).toBeInTheDocument();
expect(await accessErrorOf(() => renderServer(<Page params={params({ slug: ["green", "steeping"] })} />))).toBe(404);
expect(await accessErrorOf(() => renderServer(<Page params={params({ slug: ["brewing"] })} />))).toBe(404);
await renderServer(<Page params={params({ slug: ["green", "brewing", "cold"] })} />);
const trail = within(screen.getByRole("navigation", { name: "Breadcrumb" }));
expect(trail.getAllByRole("link").map((link) => [link.textContent, link.getAttribute("href")])).toEqual([
["Guides", "/guides"],
["Green tea", "/guides/green"],
["Brewing green tea", "/guides/green/brewing"],
]);
expect(trail.getByText("Cold brewing green tea").closest("a")).toBeNull();
expect(trail.getAllByRole("listitem").length).toBe(4);
await renderServer(<Page params={params({ slug: ["oolong"] })} />);
const trail = within(screen.getByRole("navigation", { name: "Breadcrumb" }));
expect(trail.getAllByRole("link").map((link) => link.getAttribute("href"))).toEqual(["/guides"]);
expect(trail.getAllByRole("listitem").map((item) => item.textContent)).toEqual(["Guides", "Oolong tea"]);
expect(await generateStaticParams()).toEqual([
{ slug: ["green"] },
{ slug: ["green", "brewing"] },
{ slug: ["green", "brewing", "cold"] },
{ slug: ["oolong"] },
{ slug: ["oolong", "brewing"] },
]);
Run tests runs every test on your code, here in your browser. The problem is solved when they all pass.
Ctrl + Enter runs the tests (⌘ + Enter on a Mac).
I'm here to help with Brewing guides at any depth. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.