Nuxt Sitemap v4.0.0
Background
Over the last couple of months I've had many issues reported with similar themes:
- Dynamic URLs are hard to work with
- It's difficult to get multiple sitemaps to show the correct URLs
- I18n has many small issues
I hope this release can resolve these. It has required replacing much of the underlying logic, please test your sitemaps after upgrading.
Features :rocket:
🥫 Sitemap Sources
The v4 introduces the official concept of 'sources' to your sitemaps.
Every URL within your sitemap will belong to a source. A source will either be a User source or a Application source.
This concept existed before v4 in different forms, v4 aims to clean them up and make working with them much easier.
For full documentation see Sitemap Sources.
🤝 Nuxt Dev Tools Integration
Nuxt Sitemap now has a dedicated tab in Nuxt Dev Tools to help you debug.
nuxt-simple-sitemap-devtools.webm
💬 More i18n Improvements
- Locale domain support (#155)
- Support pages opt-outed using
defineI18nRoute(false) (#126) - Only add trusted i18n routes, will use meta tags when prerendering
- Less aggressive filtering
- Opt-in to transform dynamic URLs
__i18nTransform: true
See the updated i18n documentation
🚀 Caching Improvements
Now utilises native route rules. By default will set up SWR rules for 10 minutes.
Learn more on the Sitemap Caching guide.
Other Improvements
Nitro Composables for better types
When creating an API endpoint that returns URLs you should use the new
// api/sitemap.ts
export default defineSitemapEventHandler(() => {
return ['/foo']
})
Prerendering Improvements
Previously prerendering was done in a Node context, this will now run in a Nitro context which will provide better consistency between prerender and runtime environments.
Video Support
Video entries are now supported properly. (#159)
⚠️ Deprecations
cacheTtl is deprecated, you should usecacheMaxAgeSeconds which is more explicit.inferStaticPagesAsRoutes is deprecated, if you were using this to opt-out of pages, you should useexcludeAppSources: true
☠️ Breaking Changes
Nuxt Hooks no longer supported
If you were using Nuxt hooks to modify the prerendered sitemap, you will need to migrate these to Nitro hooks.
export default defineNuxtConfig({
hooks: {
// old - no longer supported
'sitemap:resolved': function (ctx) {},
'sitemap:output': function (ctx) {}
},
})
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('sitemap:output', async (ctx) => {
// supported!
})
})
Multi Sitemap App Sources
By default, app sources will no longer be included in multi sitemap implementations. You will need to use
Removed deprecations
- The hook
sitemap:prerender has been removed. You should usesitemap:resolved instead. - The config
trailingSlash andsiteUrl has been removed. You should use site config, see Setting Site Config. - The config
autoAlternativeLangPrefixes has been removed. If you'd like to set up automatic alternative language prefixes use__i18nTransform .
Support my work
This release took over 40 hours. If technical SEO developer experience in Nuxt is important to you, consider supporting my work on Nuxt SEO.