Skip to content

Why are my Next.js pages not indexed by Google?

Next.js sites often lose pages to noindex left from staging, one canonical tag in the root layout, streamed 404s, and sitemaps with old addresses.

By Bruno Amorim · ·

Why your Next.js site isn't on Google

Check these in order. The first ones keep the whole site off Google. The last ones keep single pages off.

  1. The site is new. Google needs time to find a new site. Google says crawling can take a few days to a few weeks. Search Google for site: followed by your domain, such as site:example.com. If nothing shows, Google likely has none of your pages yet. URL Inspection in Search Console gives the exact answer for each page.
  2. Your domain serves a preview build. Vercel adds X-Robots-Tag: noindex to preview deployments. If your domain points at one, or you copied that header into next.config, Google skips every page. Run curl -I on a page and look for X-Robots-Tag.
  3. Metadata adds noindex. Look for robots: { index: false } in metadata or generateMetadata, often left on from staging. A notFound() call after the page starts streaming also adds noindex.
  4. robots.ts blocks the site. app/robots.ts builds /robots.txt. A disallow: '/' rule left from staging blocks every page.
  5. There is no sitemap, or Search Console doesn't have it. Next.js has no sitemap until you add app/sitemap.ts. List only addresses that return 200, in the slash style your site uses, and submit /sitemap.xml in Search Console.
  6. Content loads only in the browser, or every page shares one canonical tag. Fetch the main content on the server, so it is in the first HTML. Set alternates.canonical in each page's metadata. A canonical set only in the root layout applies to every page below it, so all your pages point at the home page.
  7. Links aren't real links. Use <Link href> for navigation. Google follows <a href> links, not click handlers that call router.push().

If only some pages are missing: the three most common reasons on Next.js

Search Console shows the reason for each page in Indexing > Pages. These three come up most on Next.js.

  1. Why it happens
    A dynamic route such as [slug] that renders a "not found" message without calling notFound() returns status 200. So does a notFound() call after streaming starts.
    The fix
    Call notFound() before streaming starts, outside <Suspense> and loading.tsx, so the route returns 404. Or check the slug in Proxy.
  2. 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.
  3. Why it happens
    Proxy (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.

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

Questions

Why does my Next.js 404 page return status 200?

The page started streaming before notFound() ran, so the 200 status was already sent. Next.js adds noindex in that case. Move the check before any <Suspense> boundary or loading.tsx, or into Proxy, to return a real 404.

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.

Sources

Which of your Next.js pages does Google skip?

Get my free report

Free for up to 500 pages. No card needed. Sign in with the Google account you use for Search Console.

Other platforms