Unknown catalog items
A matching dynamic route may refer to a book that does not exist. Look up the identifier in trusted application data and use notFound() when the requested item is absent. This separates route matching from data lookup and error handling.
Scope: Next.js 16.x candidate, App Router only, Cache Components disabled, TypeScript unless otherwise labeled. Examples are static source walkthroughs; exact framework patch and build are not verified.
app/catalog/[slug]/page.tsx (replacement)
import { notFound } from 'next/navigation';const books = [{ slug: 'moss', title: 'Moss' }, { slug: 'harbor', title: 'Harbor' }];export default async function BookPage({ params }: { params: Promise<{ slug: string }>;}) { const { slug } = await params; const book = books.find(item => item.slug === slug); if (!book) notFound(); return <main><h1>{book.title}</h1></main>;}/catalog/moss displays Moss. /catalog/unknown requests the nearest applicable not-found UI. A fixed synthetic array is sufficient for learning; no external database is needed.
Missing UI versus HTTP status
notFound terminates rendering of the relevant segment by throwing a framework-controlled error. The file convention not-found.tsx supplies a fallback. The documented HTTP status can differ between a response whose headers have already streamed (200) and a non-streamed missing response (404). Verify actual status separately from visible text. The documented not-found response also includes a noindex robots directive; inspect the emitted document rather than assuming a visible missing message controls indexing. Do not catch framework navigation errors in a broad catch block.
app/catalog/[slug]/not-found.tsx
import Link from 'next/link';export default function MissingBook() { return <main><h1>Book not found</h1><p><Link href="/catalog">Return to the catalog</Link></p></main>;}A missing title gives the visitor a clear recovery link. A real request test must check visible fallback and response status independently.
Common mistake
Do not report a service outage as a missing book. A failed data source is a different condition. A record lookup alone is also not authorization for private data.
Try it yourself
Try moss, harbor and unknown against the fixture. Add a known slug, check its title, and describe how you would distinguish a database outage from an absent item in a later project.
After this lesson, you should be able to: Validate a slug; Choose a not-found response.
Further reading: Missing segment control flow, Fallback and streamed/nonstreamed status.