generateMetadata
An async function a page or layout exports to build its metadata from route params or fetched data.
In more detail
Fetch calls inside it are deduplicated with the page's own fetches, so loading a post for the title does not query twice. Next.js waits for it before the head is complete, but can stream the rest of the page.
Example
export async function generateMetadata({ params }) {
const { slug } = await params;
const post = await getPost(slug);
return { title: post.title };
}Related terms
- Metadata API — The Next.js way to set a page's title, description, OpenGraph and other head tags by exporting a metadata object or generateMetadata function.
- Request Memoization — The first Next.js caching tier: identical fetch calls made while rendering one request are run only once.
- params — The object holding the values matched by a route's dynamic segments, such as { slug: 'hello' }.
Taught in
- Metadata API: Dynamic OpenGraph & Head Management — Next.js 15 & Modern App Router Architecture