Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Next.js 16+ · Function

generateSitemaps

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.

Since
v15.0.0

How it works

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.

Syntax

export async function generateSitemaps(): Promise<{ id: number }[]>

Parameters

NameTypeDescription
No direct parameters; call generateSitemaps to return sitemap descriptors.

Returns

An array of objects, each containing an id property.

Key points

  • Export generateSitemaps from a sitemap route when one sitemap is too large or should be partitioned.
  • Return an array, and give every sitemap descriptor an id that identifies its partition.
  • Each returned identifier contributes to a distinct sitemap URL containing that identifier.
  • A sitemap nested under the product route can expose partition 1 at /product/sitemap/1.xml.
  • A common partitioning strategy is to calculate the number of chunks, then return one descriptor per chunk.
  • Read the identifier in the default sitemap generator to select the corresponding records and build that XML document.

Common mistakes

  • The development URL pattern may differ from the production pattern; test generated sitemap URLs in the environment where they will be consumed.
  • The function's URL behavior changed in Next.js 15, so avoid relying on older development-only URL assumptions.

Example: Split a product sitemap into multiple files

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

When to use it

Partition large catalogs

A product catalog exceeds a practical single-sitemap size.

Chunk database records

Different sitemap files should correspond to separate record ranges.

Generate dynamic sitemap sets

A dynamic application needs multiple crawler-facing sitemap URLs.

  • sitemap.(xml|js|ts)
  • MetadataRoute.Sitemap

Source: generateSitemaps. Checked 2026-10-15.