Next.js SEO: A Practical Guide for the App Router

Islom BaimatovIslom BaimatovNovember 30, 202610 min read
Next.js SEO: A Practical Guide for the App Router

Short answer

Next.js is good for SEO when pages are rendered on the server and their content and metadata are in the first HTML response. In the App Router, set titles, descriptions and canonicals with the metadata object or generateMetadata, generate sitemap.ts and robots.ts, add JSON-LD in a native script tag, and prefer static generation. Avoid client-only rendering, and do not let loading.tsx hide a public page's content inside a hidden Suspense block.

Next.js is one of the better frameworks for SEO, but only if you use it the way search engines need. The rule that matters most comes from the Next.js docs themselves: "The most important thing for SEO is that page data and metadata is available on page load without JavaScript." Get that right and the rest is configuration.

Our own site, seovision.io, runs on the Next.js App Router. This guide covers the setup we use (metadata, canonicals, sitemaps, robots, structured data, Open Graph images and rendering) and four mistakes we found and fixed on our own pages, one of which hid the content of 97 public pages from crawlers.

Is Next.js good for SEO?

Yes, when pages render on the server. Next.js can produce complete HTML for every page before it reaches the browser, which is what crawlers and AI assistants read best. The Next.js docs call static generation "probably the best type of rendering strategy for SEO" and say client-side rendering "is not recommended for optimal SEO".

The risk is that Next.js also makes it easy to ship pages that look fine in a browser but arrive almost empty for a crawler. Most Next.js SEO problems come from that gap.

Set titles, descriptions and canonicals with the Metadata API

In the App Router, metadata comes from a static metadata object or an async generateMetadata function exported from a page or layout file. Both work only in Server Components, and you cannot export both from the same route segment. Next.js resolves metadata on the server, so it lands in the initial HTML.

A blog post page, for example, exports generateMetadata, awaits the route params, loads the post and returns four things: the post's SEO title, its meta description, a canonical address of /blog/ followed by the slug, and Open Graph fields with the type set to article. Because this runs on the server, every value is in the HTML before any JavaScript loads.

A few settings do most of the work:

  • metadataBase in the root layout turns relative URLs, like that canonical, into absolute ones.
  • title.template (with a required default) adds your brand to every title without repeating it in each page.
  • alternates.canonical prints the canonical link tag, and alternates.languages prints hreflang links for translated pages.
  • robots sets index and follow rules per page, for example noindex on thin utility pages.

Note that params is a Promise in current versions of Next.js, so it has to be awaited. To check what a deployed page really sends, run it through our free meta tag checker, which reads the HTML the way a crawler does.

Generate sitemap.ts and robots.ts

Next.js builds both files from code, so they stay in sync with your content.

  • app/sitemap.ts exports a function that reads your published pages and returns one entry per URL, with its absolute address and last-modified date. Next.js serves the result at /sitemap.xml.
  • app/robots.ts exports a function that returns your crawl rules, for example allow everything for all user agents except /api/ and /dashboard/, plus the absolute address of your sitemap. Next.js serves it at /robots.txt.

Google accepts up to 50,000 URLs per sitemap file. For larger sites, the generateSitemaps function splits the sitemap into several files. Robots rules can differ by user agent, which is how you decide separately on search crawlers and AI crawlers. Our robots.txt checker shows what your live file allows for each bot.

One habit worth copying: if the database read behind your sitemap fails, return an error status instead of an empty sitemap. An empty sitemap served with a 200 tells crawlers your site has no pages.

Add structured data as JSON-LD

The Next.js docs recommend rendering structured data as a script tag in your layout or page file. In practice that means three steps:

  1. Build the markup as a plain object: an @context of https://schema.org, an @type such as BlogPosting, and the fields that type needs, like the headline and the publish date.
  2. Turn it into a JSON string and replace every less-than character with its Unicode escape, so content from your database cannot close the tag early.
  3. Render it in a native script element with the type application/ld+json. Do not use the next/script component for this.

Validate the result with Google's Rich Results Test or the Schema.org validator. If you would rather not write the markup by hand, our schema markup generator produces it for common page types.

Open Graph images

Add a static opengraph-image.png file to a route segment, or generate one with an opengraph-image.tsx file that returns an ImageResponse from next/og. Generated images are statically optimized by default. Images over 8 MB for Open Graph or 5 MB for Twitter fail the build.

A page's explicit openGraph.images setting overrides the file. That override has a trap we hit ourselves, covered below. Check how a page will look when shared with the Open Graph checker.

Choose the right rendering for each page

  • Static generation for anything that does not change per visitor: articles, product pages, service pages, docs. For dynamic routes, add generateStaticParams so the pages are built ahead of time.
  • Server rendering on request for pages that must be fresh on every visit.
  • Client-side rendering only for parts of a page that search engines do not need, such as a dashboard widget.

On dynamic pages that stream, Next.js can append metadata tags to the body instead of the head. Google says Googlebot reads those correctly. Bots that only read HTML get the tags in the head, and the htmlLimitedBots setting in next.config decides which user agents count as such bots.

Images: next/image and alt text

The next/image component serves right-sized WebP images, prevents layout shift and lazy-loads by default. The alt prop is required, and Next.js describes it as text "used to describe the image for screen readers and search engines". Leave alt empty only for decorative images. From Next.js 16, the priority prop is deprecated in favor of preload, which you should set on the image that is the page's largest contentful paint, usually the hero.

Four Next.js SEO mistakes we fixed on our own site

These are real problems from seovision.io, each found by crawling our own pages the way a search engine does.

1. loading.tsx hid the content of 97 pages. A loading.tsx file wraps the page in a Suspense boundary. With streaming, the real content arrives inside a hidden block and a script swaps it in. Browsers show it, but crawlers that do not run JavaScript, and text extractors that skip hidden elements, see an empty page. On November 26, 2026, 97 of the 433 URLs in our sitemap sent their main content that way, including our tools, comparison and glossary pages. We removed loading.tsx from public pages and pre-rendered them with generateStaticParams. Our LLM HTML visibility checker shows what an AI crawler sees on a page without JavaScript.

2. Dynamic pages without generateStaticParams. 54 of our programmatic pages were rendered on every request. Their title and canonical were streamed into the body, and addresses that did not exist returned a page with a 200 status instead of a 404, which Google reports as soft 404s. Pre-rendering fixed both, and setting dynamicParams to false on routes with a fixed list of pages makes unknown addresses return a real 404.

3. An empty openGraph.images key removed the social image. On blog posts without a cover, we wanted the generated opengraph-image to fill in. Setting images to undefined inside the openGraph object was enough to suppress it, and the og:image tag disappeared from every cover-less post. The fix was to leave the images key out entirely when there is no cover.

4. A temporary redirect on the www domain. Our www to bare-domain redirect was a 307, a temporary code, set at the hosting level. We switched it to a 308. In next.config redirects, permanent set to true sends a 308 and permanent set to false sends a 307. Our guide to 301 vs 302 redirects explains why the difference matters.

A Next.js SEO checklist

  1. Every public page renders its content and metadata in the first HTML response.
  2. Titles, descriptions and canonicals come from metadata or generateMetadata, with metadataBase set.
  3. sitemap.ts lists only canonical, indexable URLs and fails loudly instead of going empty.
  4. robots.ts allows the crawlers you want, including AI crawlers if you want to be cited.
  5. JSON-LD is rendered in a native script tag with less-than characters escaped.
  6. Public pages have no loading.tsx, and dynamic routes use generateStaticParams.
  7. Unknown URLs return a real 404.
  8. Permanent redirects use permanent set to true.
  9. Every meaningful image has alt text, and the hero image is preloaded.

If pages still do not show up in Google after that, our guide to Discovered – currently not indexed covers the next step. And if you would rather have someone else keep a Next.js site in shape, SeoVision can publish articles straight into a Next.js blog and fix technical issues for you through our technical SEO service.

FAQ

Is Next.js good for SEO?

Yes, when pages are rendered on the server. Next.js can send complete HTML with content and metadata in the first response, which is what search engines and AI crawlers read best. The Next.js docs call static generation the best rendering strategy for SEO and say client-side rendering is not recommended for it.

How do I add meta tags in the Next.js App Router?

Export a static metadata object or an async generateMetadata function from a page or layout. Both run only in Server Components. Set title, description, alternates.canonical, robots and openGraph there, and set metadataBase in the root layout so relative URLs become absolute.

How do I create a sitemap in Next.js?

Add app/sitemap.ts that returns an array of URLs with lastModified dates, typed as MetadataRoute.Sitemap. Next.js serves it at /sitemap.xml. Google accepts up to 50,000 URLs per sitemap, and generateSitemaps splits larger sites into several files.

How do I add structured data in Next.js?

Render JSON-LD in a native script tag with type application/ld+json inside your page or layout, and escape the < character in the JSON string. The Next.js docs advise against next/script for this. Validate the markup with Google's Rich Results Test.

Does loading.tsx hurt SEO in Next.js?

It can. loading.tsx wraps the page in a Suspense boundary, and with streaming the real content arrives inside a hidden block that a script reveals. Crawlers that do not run JavaScript can miss it. On public pages that need to rank, render the content directly and pre-render dynamic routes with generateStaticParams.

What redirect status does Next.js use?

In next.config redirects, permanent: true sends a 308 status and permanent: false sends a 307. Google treats a 308 like a 301 permanent redirect and a 307 like a 302 temporary redirect.

Sources

  1. Next.js docs: generateMetadata
  2. Next.js docs: Metadata and OG images
  3. Next.js docs: sitemap.xml
  4. Next.js docs: robots.txt
  5. Next.js docs: opengraph-image and twitter-image
  6. Next.js docs: JSON-LD
  7. Next.js Learn: Rendering strategies for SEO
  8. Next.js docs: Image component
  9. Next.js docs: redirects

Reference: SEO & AI-search glossary · AI visibility tools compared · tool alternatives

Make SeoVision a preferred source

One tap and Google shows our articles more often in your Top Stories, Discover and AI answers. It only changes what you see, and you can undo it any time.

See if AI is citing your brand

Track how ChatGPT, Claude, Gemini and Perplexity talk about you — and get cited more.

Get started for free