Dev Helpers
← Back

Alternative dish route

Place this file at app/kitchen/[dish]/page.tsx in an App Router project.

Open this example in the interactive library

Source code

// app/kitchen/[dish]/page.tsx

import Link from "next/link";

import { notFound } from "next/navigation";

export default async function AlternativeDishRoute({
  params,
}: {
  params: Promise<{ dish: string }>;
}) {
  const menu = [
    { slug: "soup", mins: [10, 25], ingredients: ["lentils", "stock"], serves: 4 },
    { slug: "toast", mins: [3, 4], ingredients: ["bread", "oil"], serves: 2 },
  ];
  const { dish } = await params;
  const recipe = menu.find((r) => r.slug === dish);
  if (!recipe) notFound();
  return (
    <nav aria-label="Other dishes">
      {menu
        .filter((r) => r !== recipe)
        .map((r) => (
          <Link href={"/kitchen/" + r.slug} key={r.slug}>
            Try {r.slug}
          </Link>
        ))}
    </nav>
  );
}