Nuxt Sitemap: Using @nuxtjs/sitemap in Nuxt 3
Nuxt does not include a sitemap by default. The standard solution is the @nuxtjs/sitemap module, which integrates tightly with Nuxt 3 and automatically discovers your routes, including dynamic ones. It serves the sitemap at runtime (not just at build time), which means it stays current with CMS content without requiring a rebuild.
Installation and Basic Setup
Install: npx nuxi module add sitemap. Then configure in nuxt.config.ts:
The module reads the site.url config to generate absolute URLs. Static routes from your pages/ directory are discovered automatically. The sitemap is served at /sitemap.xml (or /sitemap_index.xml for multi-sitemap setups).
Adding Dynamic Routes
For dynamic routes (like /blog/[slug]), provide a sources array pointing to your data source:
Then create a server route at server/routes/__sitemap__/urls.ts that returns an array of URL objects. The module fetches this endpoint at runtime to get dynamic URLs, merges them with static routes, and outputs the complete sitemap. This is more flexible than build-time generation - your sitemap updates without rebuilding when you add new blog posts or products.
Common Nuxt Sitemap Issues
Missing site.url: Without site.url configured, the module cannot generate absolute URLs. All URLs in the sitemap will be relative paths, which is invalid XML sitemap format and will fail Google validation. Always set site.url to your production domain.
Dynamic routes not appearing: If CMS content is missing from the sitemap, verify your API endpoint is returning the correct URL format. Each URL object should have a loc property with the full path: { loc: '/blog/my-post' }.
Nuxt 2 vs Nuxt 3: The @nuxtjs/sitemap module for Nuxt 2 and Nuxt 3 are different packages with different APIs. If you migrated from Nuxt 2, reinstall the module fresh rather than just upgrading - the configuration structure changed significantly.
Related Guides
- WordPress Sitemap: Setup, Fix, and Submit Guide
- Shopify Sitemap: Location, Errors, and How to Submit It
- Wix Sitemap: How It Works and How to Submit It
- Squarespace Sitemap: How It Works and Common Fixes
- Webflow Sitemap: How It Works and How to Submit It
- Astro Sitemap: Using @astrojs/sitemap Integration
- Fix Sitemap for Nuxt