Search Engine Optimization (SEO) and social media link previews are vital for digital reach. Next.js 15 features the built-in Metadata API, allowing developers to define static or dynamic SEO tags, OpenGraph images, Twitter cards, and programmatic sitemaps directly through type-safe TypeScript interfaces.
Define static metadata by exporting a metadata object from any layout.tsx or page.tsx:
generateMetadata()For dynamic pages (e.g., /courses/[slug]), metadata depends on database content. Export an async generateMetadata() function:
sitemap.tsSearch engines discover your entire content catalog through a sitemap.xml. Create app/sitemap.ts to generate dynamic sitemaps automatically:
Next.js automatically serves this at /sitemap.xml!
app/ directory automatically generates a standardized sitemap.xml for search engines?layout.tsx versus a child page.tsx?generateMetadata() and the page component need it?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.