After installing the module, you may wonder: where do the URLs in your sitemap come from?
Every URL belongs to a source. There are two types:
For most sites, application sources handle everything automatically. You only need user sources when you have dynamic routes from a CMS or database.
Application sources are automatically generated from your Nuxt application. They provide convenience by automatically discovering URLs from your app's structure, but can be disabled if they don't match your needs.
nuxt:pages - Statically analysed pages of your applicationnuxt:prerender - URLs that were prerenderednuxt:route-rules - URLs from your route rules@nuxtjs/i18n:pages - When using the pages config with Nuxt I18n. See Nuxt I18n for more details.@nuxt/content:document-driven - When using Document Driven mode. See Nuxt Content for more details.You can disable application sources individually or all at once using the excludeAppSources config option.
export default defineNuxtConfig({
sitemap: {
// exclude all app sources
excludeAppSources: true,
}
})
export default defineNuxtConfig({
sitemap: {
// exclude static pages
excludeAppSources: ['nuxt:pages'],
}
})
User sources allow you to manually configure where your sitemap URLs come from. These are especially useful for dynamic routes that aren't using prerendering discovery.
You have several options for providing user sources:
urls FunctionFor sitemap data that only needs to be updated at build time, the urls function is the simplest solution. This function runs once during sitemap generation.
export default defineNuxtConfig({
sitemap: {
urls: async () => {
// fetch your URLs from a database or other source
const urls = await fetch('https://example.com/api/urls')
return urls
}
}
})
sources ArrayFor sitemap data that must always be up-to-date at runtime, use the sources array. Each source is a URL that gets fetched and should return either:
export default defineNuxtConfig({
sitemap: {
sources: [
// create our own API endpoints
'/api/__sitemap__/urls',
// use a static remote file
'https://cdn.example.com/my-urls.json',
// hit a remote API with credentials
['https://api.example.com/pages/urls', { headers: { Authorization: 'Bearer <token>' } }]
]
}
})
export default defineNuxtConfig({
sitemap: {
sitemaps: {
foo: {
sources: [
'/api/__sitemap__/urls/foo',
]
},
bar: {
sources: [
'/api/__sitemap__/urls/bar',
]
}
}
}
})
You can provide multiple sources, but consider implementing your own caching strategy for performance.
Learn more about working with dynamic data in the Dynamic URLs guide.
For advanced use cases like forwarding authentication headers or adding sources based on request context, see the Nitro Hooks documentation.