Feature request: Generated paths should follow the i18n custom route paths (config and macro)
Thank you for taking the time to fill out this feature request!
Description
The generated output should follow the i18n custom path set in i18n config. https://stackblitz.com/edit/nuxt-starter-i18n-timothe-kab8ad?file=nuxt.config.ts,pages/index.vue,package.json Would be nice to work with defineI18nRoute macro too
Input
export default defineNuxtConfig({
...
i18n: {
strategy: 'prefix_except_default',
customRoutes: 'config',
pages: {
index: {
fr: '/',
en: '/home',
},
other: {
fr: '/autre-page',
en: '/other-page',
},
},
},
robots: {
allow: ['/'],
disallow: ['/other'],
},
Actual output
User-agent: *
Allow: /
Allow: /en/
Disallow: /other
Disallow: /en/other
Expected output
User-agent: *
Allow: /
Allow: /en/home
Disallow: /autre-page
Disallow: /en/other-page
Hi, I agree this should be supported as the Sitemap module does support this.
PRs welcome otherwise will attempt when I have a chance.
In your feature request you used file paths, e.g. '/other'. But in the world of nuxt i18n you would use route names instead that get generated by Nuxt and can be seen in the devtools. For example /pages/other.vue becomes other, and pages/product/[id].vue becomes product-id. In nuxt-i18n you can link them e.g. <NuxtLinkLocale :to="{ name: 'product-id' , params: { id: '123' }}">Product</NuxtLinkLocale>.
I would suggest nuxt-seo to also use route names instead of paths for i18n:
robots: {
disallow: ['other', 'product-id'],
},
Btw. what you want to archive is very easy by use of inline route rules:
<script setup lang="ts">
defineI18nRoute({
paths: {
en: '/other',
fr: '/autre',
},
});
defineRouteRules({
robots: false,
});
</script>
Note that for this you need to have experimental.inlineRouteRules enabled in your nuxt config. Unfortunately tho, this feature is not working with latest Nuxt 3.16, issue: https://github.com/harlan-zw/nuxt-seo/issues/404