Skip to content

generateMetadata missing on dynamic route

Dynamic routes without generateMetadata() serve the same generic title and description on every page. A blog with 200 posts all titled “My Site” tells search engines there is one page, not 200.

Add generateMetadata() to the dynamic route file. It receives the same params as the page component.

app/blog/[slug]/page.tsx
import type { Metadata } from 'next'
type Props = { params: Promise<{ slug: string }> }
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { slug } = await params
const post = await getPost(slug)
return {
title: post.title,
description: post.excerpt,
}
}
export default async function Page({ params }: Props) {
const { slug } = await params
const post = await getPost(slug)
return <article><h1>{post.title}</h1></article>
}

View source on two different pages at the same dynamic route. Confirm that <title> and <meta name="description"> differ between them. Then re-run orino audit.