Getting Started

Data Sources

Last updated by Harlan Wilton in doc: overhaul.

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:

  • Application Sources - Automatically discovered from your Nuxt app
  • User Sources - Manually provided by you

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

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 application
  • nuxt:prerender - URLs that were prerendered
  • nuxt: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.

Disabling Application Sources

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,
  }
})

User Sources

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:

1. Build-time Sources with urls Function

For 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.

nuxt.config.ts
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
    }
  }
})

2. Runtime Sources with sources Array

For 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:

  • JSON array of sitemap URL entries
  • XML sitemap document
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>' } }]
    ]
  }
})

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.

3. Dynamic Sources Using Nitro Hooks

For advanced use cases like forwarding authentication headers or adding sources based on request context, see the Nitro Hooks documentation.

Did this page help you?