Home
Next.js
Next.js: Sitemap
Daniel Nguyen
Daniel Nguyen
May 01, 2026
1 min

A sitemap helps search engine crawlers discover the important URLs on your website more efficiently.

In Next.js App Router, you can generate a sitemap automatically using sitemap.ts.

1. Create a Sitemap

Create:

app/
└── sitemap.ts

Then export a function that returns your website URLs:

import type { MetadataRoute } from 'next'
export default function sitemap(): MetadataRoute.Sitemap {
return [
{
url: 'https://example.com',
lastModified: new Date(),
},
{
url: 'https://example.com/about',
lastModified: new Date(),
},
{
url: 'https://example.com/blog',
lastModified: new Date(),
},
]
}

Next.js automatically generates:

https://example.com/sitemap.xml

2. Sitemap with Dynamic Data

For an ecommerce website, URLs usually come from a database.

export default async function sitemap() {
const products = await getProducts()
return products.map((product) => ({
url: `https://example.com/products/${product.slug}`,
lastModified: product.updatedAt,
}))
}

Now when a new product is added, the sitemap can include it automatically.

Database → API → Sitemap → Search Engine

3. Useful Sitemap Properties

Each URL can contain additional information:

{
url: 'https://example.com/blog',
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.8,
}

Available properties include:

url
lastModified
changeFrequency
priority
alternates
images
videos

4. Check Your Sitemap

After deploying, open https://example.com/sitemap.xml to confirm it is generated.

To inspect it in more detail, use SitemapKit’s Sitemap Extractor. Enter your sitemap URL, and it lists every URL with its lastmod, changefreq, and priority values (the XML names for lastModified, changeFrequency, and priority). It also follows sitemap index files, counts duplicate URLs, and lets you download the list as CSV, TXT, or JSON.

This is a quick way to check that dynamic pages, such as products or blog posts, actually appear in the sitemap.


Tags

#NextJS

Share

Daniel Nguyen

Daniel Nguyen

Frontend Developer

Frontend developer specializing in React, Next.js, and JavaScript. Writing practical guides on modern web development at Dev98.

Expertise

React
Next.js
JavaScript
TypeScript
Python

Social Media

githublinkedinyoutubewebsite

Related Posts

Next.js
Supabase: Clients in Next.js
October 30, 2026
2 min
Dev98

Dev98

React · Next.js · Web development