Out of the box, the robots module will integrate directly with @nuxtjs/i18n. You will need to use v8+ of the i18n module. Alternatively, nuxt-i18n-micro (v1+) is also supported.
Auto-localized Allow / Disallow
The module will automatically localize the allow and disallow paths based on your i18n configuration.
If you provide an allow or disallow path that is not localized, it will be localized for you, if your
i18n configuration allows it.
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: /secret
Disallow: /admin
Disallow: /en/secret
Disallow: /en/admin
Disallow: /fr/secret
Disallow: /fr/adminOpting-out of localization
If you want to opt-out of localization, there are two options:
Opt-out for a group
You can provide the _skipI18n option to a group to disable localization just for that group.
nuxt.config.ts
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 autoI18n: false option you will disable all i18n localization splitting.
nuxt.config.ts
export default defineNuxtConfig({
robots: {
autoI18n: false,
}
})Was this page helpful?