Functions

Dynamic metadata function

Resolve public route data, handle missing records, and inspect streamed metadata. Source: https://nextjs.org/docs/app/api-reference/functions/generate-metadata

Formal Syntax & Structure

nextjs syntaxnextjs
export async function generateMetadata(props): Promise<Metadata>

Working Example

Example Snippetnextjs
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.'};}
Next.js Reference