Generate a sitemap
A route needs a crawler-readable sitemap generated from application data.
Next.js 16+ · Type Alias
MetadataRoute provides TypeScript types for Next.js App Router metadata file conventions. Use members such as Sitemap, Robots, and Manifest to type generated metadata results.
MetadataRoute is the namespace of TypeScript types used by Next.js metadata file conventions. Use its members—such as Sitemap, Robots, or Manifest—to type the value returned by a corresponding special file.
import type { MetadataRoute } from 'next'
MetadataRoute.Sitemap
MetadataRoute.Robots
MetadataRoute.ManifestA namespace of TypeScript types for metadata file outputs; individual members describe sitemap, robots, and manifest results.
import type { MetadataRoute } from 'next'
export default function sitemap(): MetadataRoute.Sitemap {
return [
{
url: 'https://example.com',
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 1,
},
]
}A special sitemap file can return a typed array of URL entries for crawler indexing.
A route needs a crawler-readable sitemap generated from application data.
A site needs crawler access rules and sitemap declarations.
A progressive web app needs a web app manifest returned from app/manifest.ts.
MetadataRoute is a TypeScript namespace containing types for metadata file outputs. For example, a sitemap function can return MetadataRoute.Sitemap, while robots and manifest files can use their corresponding members.
Follow-up: How would you type a dynamically generated sitemap? Return MetadataRoute.Sitemap from the default-exported function and build the array from your data source.
A sitemap file exports a default function that returns an array of URL records. MetadataRoute.Sitemap supplies the return type for that array and its supported fields.
Follow-up: What does the sitemap convention provide to crawlers? It produces sitemap XML that helps search engines index site URLs more efficiently.
The App Router supports static or dynamic metadata files such as manifest files. A manifest function can return MetadataRoute.Manifest, allowing the result to be checked against the manifest shape.
Follow-up: Can the manifest be static instead? Yes; the documentation also supports a manifest.json file alongside the TypeScript function form.
MetadataRoute.SitemapMetadataRoute.RobotsMetadataRoute.Manifestsitemap.(js|ts)robots.jsrobots.tsmanifest.tsmanifest.json