Next.js pages not indexed: causes and fixes

Next.js sites often lose pages for three reasons: pages built in the browser, missing pages that return 200, and sitemaps that list old addresses.

The three most common reasons on Next.js

Soft 404

Why it happens: A dynamic route such as [slug] that renders a "not found" message without calling notFound() returns status 200, so Google sees an empty success page.

The fix: Call notFound() when the data does not exist, so the route returns 404.

Page indexed without content

Why it happens: If a page loads its content in the browser, Google first sees an empty page or a loading spinner.

The fix: Build the main content on the server, with Server Components, static pages, or server-side rendering.

Page with redirect

Why it happens: Middleware and trailingSlash settings send visitors to a different address than the one in your sitemap.

The fix: List each page in your sitemap at the exact address your site uses: the same slash at the end, and the same domain.

Where your sitemap is

In the App Router, app/sitemap.ts makes /sitemap.xml and app/robots.ts makes /robots.txt. You have neither until you add them.

Settings that hide pages on Next.js

  • robots: { index: false } in metadata or generateMetadata, often left on from a preview build.
  • An X-Robots-Tag: noindex header, set in next.config or by your host on preview builds.
  • Preview builds on your host's own domain. Keep them off Google with noindex, not by blocking them in robots.txt.

To tell Bing about changes too, see IndexNow on Next.js.

Questions

Does Google render client-side Next.js pages?

Google can run JavaScript, but it does it later and less often. Pages built on the server get on Google faster and more often.

Do I need both sitemap.ts and robots.ts?

Yes. robots.ts should list the sitemap URL, and sitemap.ts should list only URLs that return 200.

Other platforms