Dynamic metadata
What you need to know
Use generateMetadata when the title or description depends on route data. It runs on the server and can return metadata synchronously or return a Promise. Use an async function when the route parameters or data lookup require awaiting; select the same validated public record as the page.
By the end, you can: generate metadata from validated public data; handle missing records.
Metadata for one known public guide
import type {Metadata} from 'next';import {notFound} from 'next/navigation';export async function generateMetadata({params}:{params:Promise<{slug:string}>}):Promise<Metadata>{ const {slug}=await params; if(slug!=='river-walks') notFound(); return {title:'River Walks',description:'A short guide to riverside walks.'};}Expected behavior: Known slug receives public metadata; other slugs enter the not-found path. This is a partial page module.
How it works
In the Next.js 16 App Router teaching lane, params is asynchronous. Await it, resolve a bounded public identifier, and handle missing or unpublished records consistently. Do not fetch a URL derived from an arbitrary slug or include private fields in the result. A missing route can call notFound; Next.js adds a noindex directive for this convention, but a streamed response can already have committed status 200. Verify the response and HTML in the intended rendering mode. Metadata may arrive after initial UI for dynamically rendered routes. HTML-limited crawlers receive special handling, controlled by framework defaults and the htmlLimitedBots option; do not claim every user agent receives the same initial markup. If a parent openGraph object must be extended, explicitly retain the required fields. Avoid using metadata functions for writes or expensive repeated work. For a real data source choose appropriate memoization/caching and permission checks and verify that no private values cross into public metadata.
Inspect a metadata response locally
curl -i --max-time 5 http://127.0.0.1:3100/en/catalog/river-walkscurl -i --max-time 5 http://127.0.0.1:3100/en/catalog/missingExpected behavior: Compare status, title, robots directive and actual body after a compatible staged app is running. Streaming behavior requires inspecting complete responses.
Common mistake
Do not silently fall back to a real book title for an unknown slug. Do not copy full private records into metadata or assume that a screenshot proves crawler-visible output.
Practice and verification
Write a route matrix with a known public slug, unknown slug and a draft. Specify expected title, canonical, body and indexing policy. Test full response and browser head independently after framework setup.
Scope: Proposed Next.js 16.x / React 19, Cache Components disabled unless noted. Framework and browser examples are staged; local standalone tests are reported separately. Exact dependency patches and platform contracts pending.