Metadata exports
What you need to know
The App Router Metadata API supplies document titles, descriptions and related head elements. Use a static metadata export when the values are known without fetching route-specific data.
By the end, you can: choose static metadata; explain route ownership.
Set a root title template
import type {Metadata} from 'next';export const metadata: Metadata = { metadataBase: new URL('https://books.example'), title:{default:'River Books',template:'%s | River Books'}, description:'An independent catalog of reading guides.'};export default function Layout({children}:{children:React.ReactNode}) { return <html lang='en'><body>{children}</body></html>;}Expected behavior: Root defaults are supplied. A child segment with title Catalog should receive Catalog | River Books.
How it works
A layout can define defaults for descendant segments, and a page can supply its own values. Both metadata and generateMetadata belong in Server Components; choose one per segment file rather than exporting both. A title template in a layout formats titles in child segments, not the title defined in a page at the same segment. Supply a default title for routes without their own title. Metadata fields are evaluated by route hierarchy; nested objects such as openGraph are not automatically deep merged. File-based metadata may take precedence over a programmatic value. Set metadataBase using the approved public origin rather than a user-supplied Host header. Use a fictional origin only in a local exercise, replace it deliberately before publishing. A document title identifies the page in browser tabs and other contexts; it does not replace the visible heading. Inspect the actual output rather than assuming any object maps exactly to HTML. Dynamic generateMetadata may stream separately from the initial UI; documented HTML-limited crawlers receive blocking metadata instead. Do not equate the first response chunk with the completed metadata. Check the exact release and both client classes.
Override a child page title
import type {Metadata} from 'next';export const metadata:Metadata={title:'Catalog',description:'Browse public reading guides.'};export default function Page(){return <h1>Catalog</h1>;}Expected behavior: Place in app/catalog/page.tsx under the root layout; expected title is Catalog | River Books, with a matching visible heading.
Common mistake
Do not add use client to a file exporting metadata. Do not assume a title template affects the same segment or that nested metadata objects merge field by field.
Practice and verification
Add a Help page to a staged tree, set a specific description and predict the final title. Verify the actual head after a production build, including the root and a child page.
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.