The Metadata API replaces manual <Head> management with type-safe exports from layouts and pages for SEO and social sharing.
Common Interview Questions
Q: Static metadata export?
Answer: Export metadata object from layout.tsx or page.tsx. Next.js merges metadata down the tree with child overrides.
export const metadata = {
title: "BugCast Blog",
description: "Interview prep for developers",
openGraph: { title: "BugCast", images: ["/og.png"] },
};
Q: Dynamic metadata?
Answer: Async function fetches data per route for dynamic titles and OG tags — essential for blog and product pages.
export async function generateMetadata({ params }) {
const post = await getPost(params.slug);
return { title: post.title, description: post.excerpt };
}
Q: title template?
Answer: Child pages set title: 'About' and render as About | BugCast.
export const metadata = {
title: { default: "BugCast", template: "%s | BugCast" },
};
Q: robots and sitemap?
Answer: Use app/robots.ts and app/sitemap.ts route handlers that export config functions returning rules and URL lists.
Key Points for Interviews
-
Metadata merges parent → child with overrides
-
generateMetadata for dynamic routes
-
Open Graph and Twitter cards built-in
-
Prefer Metadata API over next/head in App Router
-
Structured data via JSON-LD script tags when needed
