DEV Community

Joodi
Joodi

Posted on

Dynamic SEO in Next.js with generateMetadata()

One feature I really like in the Next.js App Router is **generateMetadata()**.

Instead of hardcoding page titles and descriptions, you can fetch data and generate SEO metadata dynamically.

export async function generateMetadata({ params }) {
  const post = await fetchPost(params.slug);

  return {
    title: post.title,
    description: post.excerpt,
  };
}
Enter fullscreen mode Exit fullscreen mode

This is especially useful for:
β€’ Blog posts
β€’ Product pages
β€’ CMS-driven content
β€’ Dynamic routes

Your metadata stays in sync with your content, and each page gets its own SEO data automatically.

Small feature, but it makes building dynamic websites much cleaner.

Top comments (0)