Nuxt Prerendering
When prerendering routes using Nuxt through either nuxi generate
or using the prerender options, the module
will extract data from the generated HTML and add it to the sitemap.
This can be useful if you have dynamic routes that you want to be included in the sitemap and want to minimise your configuration.
Extracted HTML Data
The following data can be extracted from the raw HTML.
images
- Adds image entries<image:image>
.
Passes any <img>
tags within the <main>
tag. Requires discoverImages
to be enabled.
lastmod
- Adds lastmod date<lastmod>
.
Uses the opengraph article:modified_time
and article:published_time
meta tag.
Enabling Nuxt Prerendering
You will need to use configuration to enable this feature.
export default defineNuxtConfig({
nitro: {
prerender: {
// enabled by default with nuxt generate, not required
crawlLinks: true,
// add any routes to prerender
routes: ['/']
}
}
})
You can also use route rules to enable prerendering for specific routes.
export default defineNuxtConfig({
routeRules: {
'/': { prerender: true }
}
})
Prerendering the Sitemap on Build
If you're using nuxi build
and want to prerender the sitemap on build, you can add the sitemap path to the nitro.prerender.routes
option.
export default defineNuxtConfig({
nitro: {
prerender: {
routes: ['/sitemap.xml']
}
}
})