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

Taught in

References