Nuxt I18n
How to use the Nuxt Robots module with Nuxt I18n.
Out of the box, the robots module will integrate directly with @nuxtjs/i18n. You will need to use v8+ of the i18n module.
Auto-localised Allow / Disallow
The module will automatically localise the
If you provide a
nuxt.config.ts
export default defineNuxtConfig({
robots: {
disallow: ['/secret', '/admin'],
},
i18n: {
locales: ['en', 'fr'],
defaultLocale: 'en',
strategy: 'prefix',
}
})
This will generate the following output:
robots.txt
User-agent: *
Disallow: /en/secret
Disallow: /en/admin
Disallow: /fr/secret
Disallow: /fr/admin
Opting-out of localisation
If you want to opt-out of localisation, there are two options:
Opt-out for a group
You can provide the
export default defineNuxtConfig({
robots: {
groups: [
{
disallow: [
'/docs/en/v*',
'/docs/zh/v*',
'/forum/admin/',
'/forum/auth/',
],
_skipI18n: true,
},
],
},
})
Opt-out i18n globally
By providing the
export default defineNuxtConfig({
robots: {
autoI18n: false,
}
})
Did this page help you?