Dec 2026 · Guide · ~8 min read
Next.js Metadata — Titles, Descriptions, and Canonical URLs
By Safdar Ali — frontend engineer, Bengaluru
I'm Safdar Ali. The metadata export on a page is what ends up in the head. A shared layout title with no page title means every URL looks the same in a search result. I set a title and description on each route that is meant to be indexed.
The canonical URL is the one you want indexed. Query-string copies and trailing-slash variants should point at it. This site sets metadataBase in the root layout and a canonical on the article. Without that, a rewritten host or a preview deployment can advertise the wrong origin.
Open Graph fields are the card when someone pastes the link. Use the same facts as the page, not a marketing line that the article does not support. A generated image is fine. A default image for every post is also fine if the title is specific.
Do not put a keyword list in the copy as a substitute. The description should be a sentence a person would click. I write it after the article, from the article, in one or two lines.
Unpublished or private routes should not be in the sitemap and should ask not to be indexed. A metadata title on a 404 that still says index, follow is how empty pages enter the index.
If this helped you
I publish free tutorials and write-ups like this in my spare time — no paywall on the guides. If it saved you an afternoon of trial and error, you can support the work:
- Buy me a coffee at buymeacoffee.com/safdarali
- Subscribe to my YouTube channel — it's free; 70+ React & Next.js tutorials
Related reading
More guides on safdarali.in — same author, production-focused.
- Guide
How to Build a Frontend Developer Portfolio That Stands Out
Frontend developer portfolio guide for India — sections, React/Next.js examples, SEO, performance, personal branding, FAQ, and checklist to build and rank.
May 2026Read article →
- Guide
React Server Components vs Client Components — When to Use Which
Practical RSC vs client guide for Next.js App Router — when to use each, real code, bundle before/after, and performance impact.
May 2026Read article →