# 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.

Canonical: https://scaplet.com/seo/nextjs/xml-sitemap

Guide Next.js Next.js · Crawling

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 with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2Fxml-sitemap%20(%22Next.js%20XML%20sitemap%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2Fxml-sitemap%20(%22Next.js%20XML%20sitemap%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2Fxml-sitemap%20(%22Next.js%20XML%20sitemap%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnextjs%2Fxml-sitemap%20(%22Next.js%20XML%20sitemap%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

On this page

## 4 parts, 4 minutes.

1. [Use the metadata route for generated URLs 01](#use-the-metadata-route-for-generated-urls)
2. [Keep the sitemap accurate 02](#keep-the-sitemap-accurate)
3. [Split a large catalog before the limit 03](#split-a-large-catalog-before-the-limit)
4. [Verify the route after deployment 04](#verify-the-route-after-deployment)

_01_Check 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](/glossary/indexability) 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, })) }
```

_02_Worth 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](/glossary/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](/glossary/google-search-console) and review parsing errors; the [URL Inspection tool](/glossary/url-inspection-tool) can help with a specific page, while the sitemap report is for the submitted file.

_03_Check 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](/glossary/xml-sitemap), 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, })) }
```

_04_How 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.

**Do not publish every database row**Sitemap generation can make a large URL set discoverable quickly. Filter out drafts, duplicate facets, expired offers, and URLs that resolve to redirects or errors before returning the array.

If you use the Pages Router, verify its route conventions separately; this guide covers the App Router metadata file. Continue with [Next.js redirects](/seo/nextjs/redirects), the [Google Search Console sitemap submission guide](/seo/google-search-console/sitemap-submission), and [Next.js robots.txt](/seo/nextjs/robots-txt) for discovery and crawling checks.

Questions

## Asked a lot.

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

_01_ Where 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`.

_02_ How 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.

_03_ Does 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. 01 [Metadata Files: sitemap.xml | Next.js Documentation](https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap) nextjs.org · checked 2026-10-24
2. 02 [generateSitemaps | Next.js Documentation](https://nextjs.org/docs/app/api-reference/functions/generate-sitemaps) nextjs.org · checked 2026-10-24
3. 03 [Build and submit a sitemap | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/sitemaps/build-sitemap) developers.google.com · checked 2026-10-24

## Keep learning

[All platform guides](/seo)

[Learn Next.js SEO Frameworks](/seo/nextjs) [Related Google Search Console Crawling and indexing](/glossary/google-search-console) [Read next Next.js canonical tags Frameworks](/seo/nextjs/canonical-tags) [Do Run a free site audit Free, about two minutes](/site-audit)

Nearby in platform guides
[Nginx custom 404 page](/seo/nginx/404) [Nuxt SEO](/seo/nuxt)

More in Next.js SEO
[Next.js 404 page](/seo/nextjs/404) [Next.js AI crawlers](/seo/nextjs/ai-crawlers) [Next.js canonical tags](/seo/nextjs/canonical-tags) [Next.js Google Analytics](/seo/nextjs/google-analytics) [Next.js image SEO](/seo/nextjs/image-seo) [Next.js lazy loading](/seo/nextjs/lazy-loading) [Next.js noindex](/seo/nextjs/noindex) [Next.js redirects](/seo/nextjs/redirects) [Next.js robots.txt](/seo/nextjs/robots-txt) [Next.js structured data](/seo/nextjs/structured-data) [Next.js title and meta description](/seo/nextjs/title-and-meta) [Next.js XML sitemap](/seo/nextjs/xml-sitemap)

Terms on this page
[Indexability](/glossary/indexability) [Internal search](/glossary/internal-search) [Google Search Console](/glossary/google-search-console) [URL Inspection tool](/glossary/url-inspection-tool) [XML sitemap](/glossary/xml-sitemap)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

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

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
