Free auditStart free
GuideNext.js · Crawling

Next.js XML sitemap

Build a Next.js App Router sitemap with the metadata route, split large URL sets, and verify canonical URLs and sitemap limits.

4 min
read
3
sources
Oct 24, 2026
updated
Scaplet Editorial Team
author
In one line

For an App Router site, add app/sitemap.ts and return a MetadataRoute.Sitemap array of absolute URLs. For a small site, a static app/sitemap.xml also works. Split large URL sets before they exceed Google's 50,000 URL or 50 MB uncompressed limits, and include only canonical URLs you want crawled; a sitemap helps discovery but does not guarantee indexing.

30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
01Check it

Use the metadata route for generated URLs

Next.js supports a static app/sitemap.xml file for smaller applications and a special app/sitemap.ts file when the URL list comes from your app. The metadata route returns a MetadataRoute.Sitemap array and is available at /sitemap.xml. Generate absolute URLs from the production site origin, and source the list from pages that are public and intended for search.

Replace getPublishedPages() with your CMS query. This example assumes it returns published, indexable pages and a meaningful update date. If your app uses localized URLs, Next.js supports language alternates on sitemap entries; generate each canonical locale URL from the same source of truth.

app/sitemap.ts
import type { MetadataRoute } from 'next'

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const pages = await getPublishedPages()

  return pages.map((page) => ({
    url: `https://example.com/${page.slug}`,
    lastModified: page.updatedAt,
  }))
}
02Worth knowing

Keep the sitemap accurate

Use the canonical production URL

Do not put preview hosts, localhost, duplicate host variants, or redirected URLs in the sitemap.

Exclude pages that should not be indexed

Drafts, internal search results, account pages, and duplicate filtered views generally do not belong in a public discovery list.

Use `lastModified` only when it is real

Next.js serializes sitemap metadata such as last modification dates. Google uses lastmod when it is consistently and verifiably accurate; do not stamp every URL with the current build date if the page did not change.

Do not treat priority and change frequency as ranking controls

Google says it ignores these optional values.

Keep the sitemap aligned with internal links and canonicals

A sitemap can expose an orphan, but it does not make that page useful or guarantee it will be indexed.

Google supports the sitemap formats defined by the Sitemaps protocol and says each has its own benefits, so pick the one that fits your site. Google calls submitting a sitemap a hint: it does not guarantee that Google will download the sitemap or use it for crawling. Submit the file in Search Console and review parsing errors; the URL Inspection tool can help with a specific page, while the sitemap report is for the submitted file.

03Check it

Split a large catalog before the limit

Google's sitemap limit is 50,000 URLs or 50 MB uncompressed per sitemap. Next.js documents generateSitemaps for generating multiple sitemap files. For a growing catalog, partition by stable content groups such as products, articles, and locations, and keep each generated file comfortably below both limits.

Keep partition IDs deterministic so a deploy does not unpredictably move URLs between files. Put the file where its URLs should live: Next.js serves the generated sitemaps at /.../sitemap/[id].xml, for example /product/sitemap/1.xml for app/product/sitemap.ts. Since Next.js 16 the id is passed to the sitemap function as a promise that resolves to a string; earlier versions pass a plain string, and await works on both. The Next.js docs do not describe generating a sitemap index, so list each file in Search Console or in robots.ts (its sitemap field accepts an array), or write an index yourself. Google says you can submit multiple sitemaps and index files.

Multiple sitemaps with generateSitemaps
import type { MetadataRoute } from 'next'

export async function generateSitemaps() {
  const count = await getSitemapPartitionCount()
  return Array.from({ length: count }, (_, id) => ({ id }))
}

export default async function sitemap(props: {
  id: Promise<string>
}): Promise<MetadataRoute.Sitemap> {
  const id = Number(await props.id)
  const pages = await getPublishedPagesForPartition(id)
  return pages.map((page) => ({
    url: `https://example.com/${page.slug}`,
    lastModified: page.updatedAt,
  }))
}
04How it works

Verify the route after deployment

  1. 1

    Open the public sitemap

    Visit https://example.com/sitemap.xml and confirm it returns XML with absolute production URLs, not an HTML error page.

  2. 2

    Check a sample of entries

    Choose one page from each data source or partition. Confirm it returns a successful response, has the intended canonical, is not blocked from crawling, and is intended for indexing.

  3. 3

    Validate scale and dates

    Count the URLs and check uncompressed size for each sitemap. Compare lastmod with actual content updates rather than deployment time.

  4. 4

    Submit and monitor

    Add the sitemap in Search Console. Review the sitemap report for read or parsing issues, then inspect individual important URLs separately.

If you use the Pages Router, verify its route conventions separately; this guide covers the App Router metadata file. Continue with Next.js redirects, the Google Search Console sitemap submission guide, and Next.js robots.txt for discovery and crawling checks.

Questions

Asked a lot.

3 questions people ask next, answered from the sources on this page.

01Where does a Next.js sitemap file go?

For the App Router, place a static sitemap at app/sitemap.xml or return a generated sitemap from app/sitemap.ts. Next.js exposes the generated metadata route at /sitemap.xml.

02How many URLs can one sitemap contain?

Google allows up to 50,000 URLs or 50 MB uncompressed per sitemap. Split the URL set into multiple files and use a sitemap index when needed.

03Does adding a URL to a sitemap make Google index it?

No. A sitemap helps Google discover URLs, but submission does not guarantee crawling or indexing. Keep the page useful, canonical, crawlable, and linked from relevant pages.

Sources · 3

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • nextjs.org
  • google.com
  1. 01Metadata Files: sitemap.xml | Next.js Documentationnextjs.org · checked 2026-10-24
  2. 02generateSitemaps | Next.js Documentationnextjs.org · checked 2026-10-24
  3. 03Build and submit a sitemap | Google Search Centraldevelopers.google.com · checked 2026-10-24
Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane