SEO by platform · Updated
Next.js SEO: metadata, sitemaps and rendering
Next.js is one of the best React setups for SEO because pages render on the server by default in the App Router. The work is using its Metadata API for titles, descriptions and canonicals, generating a sitemap and robots.txt, and keeping content out of client-only components.

Founder, SEO·AEO·GEO
Builds SEO·AEO·GEO and writes the crawler, schema, and citation research published here.
How Next.js serves pages to crawlers
In the App Router, components are Server Components by default and pages are rendered to HTML on the server or at build time. Client Components are also rendered to HTML on the first request, but anything fetched only in the browser (in useEffect, for example) isn't in that HTML.
Titles, descriptions and canonicals
Use the Metadata API: export a metadata object from a layout or page, or a generateMetadata function for dynamic routes. Next.js puts the tags in the <head>.
// app/blog/[slug]/page.tsx
export async function generateMetadata({ params }) {
const post = await getPost((await params).slug)
return {
title: post.seoTitle,
description: post.description,
alternates: { canonical: `https://example.com/blog/${post.slug}` },
openGraph: { title: post.seoTitle, description: post.description },
}
}next-seo is a community package for the older Pages Router. In the App Router, the built-in Metadata API replaces it.
sitemap.ts and robots.ts
// app/sitemap.ts
export default async function sitemap() {
const posts = await getPosts()
return posts.map((p) => ({ url: `https://example.com/blog/${p.slug}`, lastModified: p.updatedAt }))
}
// app/robots.ts
export default function robots() {
return {
rules: [{ userAgent: '*', allow: '/' }],
sitemap: 'https://example.com/sitemap.xml',
}
}Checklist
- Fetch page content on the server (in Server Components or at build time), not in useEffect.
- Use generateStaticParams for content pages so they're prebuilt.
- Return notFound() for missing items, so they get a real 404 status.
- Use next/link for internal links; it renders real <a href> elements.
- Add JSON-LD in a <script type="application/ld+json"> rendered by the page.
- Use next/image with width and height to avoid layout shift.
- Check the HTML with JavaScript disabled to confirm titles and content are there.
Next.js and AI search
- Check robots.txt allows the AI search crawlers you want: OAI-SearchBot (ChatGPT search), Claude-SearchBot, PerplexityBot. See the AI crawler list and the robots.txt generator.
- Check your host's or CDN's bot protection doesn't block them even when robots.txt allows them.
- Make sure the main text is in the HTML the server sends. AI crawlers don't run JavaScript.
- Avoid nosnippet and tiny max-snippet values on pages you want quoted; they also keep pages out of Google's AI Overviews.
Check it on your own site
What the free audit tests for this
- Raw HTML visibility
- Title tag
- Meta description
- Canonical
- sitemap.xml
- Schema.org / JSON-LD
One URL, about 20 seconds, no login. You get the result of every check and the exact fix for the top three issues.
Audit your website freeFAQ
Is Next.js good for SEO?+
Yes. Server rendering and static generation put full HTML in front of crawlers, and the Metadata API, sitemap.ts and robots.ts cover the technical basics.
Do I still need next-seo?+
Not with the App Router; its built-in Metadata API does the same job. next-seo is mainly used with the Pages Router.
Are Client Components bad for SEO?+
No. They're rendered to HTML on the first request. Content that's fetched only in the browser after load is the problem.
Sources
- Metadata and OG images — Next.js Docs
- sitemap.xml — Next.js Docs
- robots.txt — Next.js Docs
- Understand JavaScript SEO basics — Google Search Central