Nuxt module
Sitemap
Four kinds of sitemap entry sources and the nuances of serving them.
Sitemap: four sources of entries
- Static routes — the module scans
app/pages/**at build time; dynamic files ([id].vue) are excluded. - Static entries —
{ loc, lastmod?, changefreq?, priority? }objects right insources. - URL sources — strings (
'/api/seo/urls'): the route$fetches them on every request. - Function sources —
async () => SitemapSourceEntry[]. Serialized into the server bundle viatoString()into a Nitro virtual module, so the function must be self-contained: Nitro globals ($fetch) are available, closures over nuxt.config variables are not. A non-serializable (bound/native) function fails the build with a clear error.
Nuances: a failing source → console.warn + serve what was collected (a partial sitemap beats a 500). loc is absolutized against site.url, entries are deduplicated, XML is escaped. The path is added to nitro prerender — with nuxt generate sources are queried at build time.
sitemap: { autoRoutes: false } drops the automatic routes collected from app/pages — use it with explicit sources when routes need locale prefixes or manual curation (i18n / multi-app setups).