Sitemap
Getting Started

Data Sources

Learn how the Nuxt Sitemap sources work.

Every URL within your sitemap will belong to a source.

A source will either be a User source or a Application source.

Application Sources

Application sources are sources generated automatically from your app. These are in place to make using the module more convenient but may get in the way.

  • nuxt:pages - Statically analyzed 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 opt out of application sources individually or all of them by using the excludeAppSources config.

export default defineNuxtConfig({
  sitemap: {
    // exclude all app sources
    excludeAppSources: true,
  }
})

User Sources

When working with a site that has dynamic routes that isn't using prerendering discovery, you will need to provide your own sources.

For this, you have a few options:

1. Build time: provide a urls function

If you only need your sitemap data concurrent when you build, then providing a urls function is the simplest way to provide your own sources.

This function will only be run when the sitemap is generated.

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: provide a sources array

If you need your sitemap data to always be up-to-date at runtime, you will need to provide your own sources explicitly.

A source is a URL that will be fetched and is expected to return an array of Sitemap URL entries.

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 any number of sources, however, you should consider your own caching strategy.

You can learn more about data sources on the Dynamic URLs guide.