site.trailingSlash config—Nuxt SEO applies it to sitemaps and canonicalsA trailing slash is the "/" at the end of a URL:
/about//aboutWhile trailing slashes don't directly impact SEO rankings, they can create technical challenges:
/about and /about/ serve the same content without proper canonicalization, search engines have to choose which version to index. While Google is generally good at figuring this out, it's better to be explicit.The solution is simple: pick one format and stick to it by redirecting the other and set canonical URLs.
Nuxt handles trailing slashes through the trailingSlash option in nuxt.config.ts:
export default defineNuxtConfig({
// Default behavior - trailing slashes are removed
})
By default, Nuxt removes trailing slashes from URLs.
export default defineNuxtConfig({
site: {
trailingSlash: true
}
})
This will automatically add trailing slashes to your sitemap, canonical URLs, and internal links generated by Nuxt SEO modules.
If you're using Nuxt SEO Utils, the trailingSlash configuration is handled automatically:
export default defineNuxtConfig({
site: {
trailingSlash: true, // or false
}
})
Nuxt SEO will:
<SiteLink> ComponentFor internal links, use the <SiteLink> component instead of <NuxtLink>. It automatically applies the correct trailing slash format:
<template>
<!-- Will be /about/ if trailingSlash is enabled -->
<!-- Will be /about if trailingSlash is disabled -->
<SiteLink to="/about">
About
</SiteLink>
</template>
withBase - Adds the app.baseURL to the linkabsolute - Renders the link as an absolute pathUse routeRules to enforce redirects for inconsistent URLs:
export default defineNuxtConfig({
routeRules: {
// Redirect trailing slash URLs
'/**/**/': { redirect: { to: path => path.slice(0, -1), statusCode: 301 } }
}
})
export default defineNuxtConfig({
routeRules: {
// Redirect non-trailing slash URLs
'/**/': { redirect: { to: path => `${path}/`, statusCode: 301 } }
}
})
Set canonical URLs to indicate your preferred URL format:
<script setup>
useHead({
link: [
{
rel: 'canonical',
href: 'https://example.com/about' // or /about/
}
]
})
</script>
Or use useSeoMeta:
<script setup>
useSeoMeta({
canonicalUrl: 'https://example.com/about'
})
</script>
trailingSlash in nuxt.config.ts for consistency<SiteLink>: Replace <NuxtLink> with <SiteLink> for automatic trailing slash handlingrouteRules for 301 redirects of inconsistent URLs❌ Don't mix URL formats across your site ❌ Don't rely only on client-side redirects for SEO ❌ Don't ignore the issue on large sites ❌ Don't change your format without proper redirects