How do you set the page title and description for SEO in the Next.js App Router?
Short answer
You export a metadata object from your page or layout file, defining fields like title and description, and Next.js automatically generates the correct HTML head tags for search engines and social media platforms to read when they crawl or share your page.
Advertisement
AModel answer
You export a metadata object from your page or layout file, defining fields like title and description, and Next.js automatically generates the correct HTML head tags for search engines and social media platforms to read when they crawl or share your page.
// app/about/page.js
export const metadata = {
title: 'About Us | My Company',
description: 'Learn more about our mission and team.'
};
export default function AboutPage() {
return <h1>About Us</h1>;
}Real-world example
A company sets a clear, keyword rich title and description on its about page, helping it appear more attractively in search engine results when people search for the company by name.
Likely follow-ups
- Can metadata be inherited from a parent layout to child pages?
- What happens if both a layout and a page define conflicting metadata?
Related topics