Partition large catalogs
A product catalog exceeds a practical single-sitemap size.
Next.js 16+ · Function
generateSitemaps lets an App Router sitemap route produce multiple sitemap files. Return one object with an id for each partition, then use that id in the sitemap generator to create each file.
Use generateSitemaps in a sitemap.(js|ts) file to return sitemap identifiers. Next.js invokes the sitemap generator for each identifier, producing separate XML files whose routes include the identifier.
export async function generateSitemaps(): Promise<{ id: number }[]>| Name | Type | Description |
|---|---|---|
| | No direct parameters; call generateSitemaps to return sitemap descriptors. |
An array of objects, each containing an id property.
// app/product/sitemap.ts
import type { MetadataRoute } from 'next'
export async function generateSitemaps() {
return [{ id: 0 }, { id: 1 }, { id: 2 }]
}
export default async function sitemap({ id }: { id: number }) {
const start = id * 50000
const products = await fetch(
`https://api.example.com/products?start=${start}&limit=50000`
).then((response) => response.json())
return products.map((product: { slug: string }) => ({
url: `https://example.com/products/${product.slug}`,
lastModified: new Date(),
})) satisfies MetadataRoute.Sitemap
}The function declares the sitemap partitions, while the default sitemap function uses each returned ID to fetch and format that partition's URLs.
A product catalog exceeds a practical single-sitemap size.
Different sitemap files should correspond to separate record ranges.
A dynamic application needs multiple crawler-facing sitemap URLs.
sitemap.(xml|js|ts)MetadataRoute.Sitemap