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

Next.js 16+ · Type Alias

MetadataRoute

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.

How it works

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.

Syntax

import type { MetadataRoute } from 'next'

MetadataRoute.Sitemap
MetadataRoute.Robots
MetadataRoute.Manifest

Returns

A namespace of TypeScript types for metadata file outputs; individual members describe sitemap, robots, and manifest results.

Key points

  • The documented TypeScript pattern places MetadataRoute.Sitemap on the default sitemap function's return type.
  • The robots convention can be represented by a generated file, typically through a typed default function.
  • MetadataRoute.Robots is the documented return type for a TypeScript robots file.
  • Manifest metadata supports either a TypeScript implementation or a JSON file under the app directory.
  • MetadataRoute.Manifest types the value returned by a TypeScript manifest function.

Common mistakes

  • The sitemap convention is a special file convention, so place the implementation in the expected sitemap file rather than an arbitrary module.
  • Robots output must follow the Robots Exclusion Standard; its fields are interpreted by crawlers, not as general application configuration.

Example: Typed sitemap

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.

When to use it

Generate a sitemap

A route needs a crawler-readable sitemap generated from application data.

Type robots metadata

A site needs crawler access rules and sitemap declarations.

Type a web manifest

A progressive web app needs a web app manifest returned from app/manifest.ts.

Interview questions

QWhat is MetadataRoute used for?

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.

QHow do you use MetadataRoute with a sitemap?

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.

QWhich MetadataRoute members are used by other file conventions?

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.Sitemap
  • MetadataRoute.Robots
  • MetadataRoute.Manifest
  • sitemap.(js|ts)
  • robots.js
  • robots.ts
  • manifest.ts
  • manifest.json

Source: Metadata Files: sitemap.xml - Next.js. Checked 2026-10-15.