Back to Workshop resources
SEO · AEO · GEO1 min read

Sitemap.xml in Next.js — generate programmatically.

Use app/sitemap.ts to generate /sitemap.xml from your real routes. Auto-updates on every build.

Haojun See
Haojun See

Founder & Director, On The Ground

Updated 6 June 2026

Overview

A sitemap tells Google + AI crawlers what pages your site has and how often they update. Next.js generates it from a TypeScript file — no plugin needed.

The file

Create src/app/sitemap.ts exporting a default function that returns a MetadataRoute.Sitemap (array of {url, lastModified, changeFrequency, priority}).

Include dynamic routes

Map over your blog posts, articles, courses, etc. to add their URLs to the sitemap automatically.

Exclude what shouldn't be indexed

Don't include /preview/ if it's gated or noindex. Don't include /admin or password-protected routes.

Want to Apply This to Your Business?

We're a Singapore AI development and automation agency. Let's discuss how we can help solve your specific challenges.