nuxt-community / sitemap-module

Sitemap Module for Nuxt 2
https://sitemap.nuxtjs.org
MIT License
690 stars 128 forks source link

Disable i18n #147

Closed altynbek07 closed 4 years ago

altynbek07 commented 4 years ago

Version

v2.4.0

Reproduction link

https://github.com/nuxt-community/sitemap-module

Steps to reproduce

Add i18n Add sitemap Configure both according to doc

What is expected ?

I want to disable autogenerated i18n routes in sitemap. In my nuxt.config.js I setted i18n: false option in sitemap section:

// nuxt.config.js

{
  modules: [
    ['nuxt-i18n', {
      locales: [
          { code: 'ru', name: "Русский", file: 'ru.js', iso: 'ru-RU' },
          { code: 'kk', name: "Қазақша", file: 'kk.js', iso: 'kk-KZ' },
          { code: 'en', name: "English", file: 'en.js', iso: 'en-US' }
      ],
      defaultLocale: 'ru',
      // and some other i18n options
    }],
    ['@nuxtjs/sitemap', {
      // some other  sitemap options
      i18n: false
    }]
  ]
}

What is actually happening?

Sitemap still generated with i18n routes

This bug report is available on Nuxt community (#c108)
NicoPennec commented 4 years ago

Hi @altynbek07,

If you set the sitemap.i18n option at false, it's only to not group i18n routes according this spec: https://support.google.com/webmasters/answer/189077#sitemap. I have tried and with the false value it works fine. Try to set at true to understand the difference.

If you only want to hide some routes linked to a language defined from nuxt-i18n, you have to use the "exclude" option or the "filter" option of the sitemap module.

altynbek07 commented 4 years ago

@NicoPennec Yes, I meant regular i18n routes (attached a screenshot). As a temporary solution, I added this array to the exclude option and everything works as I need. But I think this is not the right way:

[
  '/kk',
  '/kk/**',

  '/en',
  '/en/**'
]

image

NicoPennec commented 4 years ago

@altynbek07 I understand more. If you don't want the routes injected by the i18n module, you just have to declare the sitemap module before it as below:

{
  modules: [
    ['@nuxtjs/sitemap', {
      // some other  sitemap options
      // i18n: false
    }],
    ['nuxt-i18n', {
      locales: [
          { code: 'ru', name: "Русский", file: 'ru.js', iso: 'ru-RU' },
          { code: 'kk', name: "Қазақша", file: 'kk.js', iso: 'kk-KZ' },
          { code: 'en', name: "English", file: 'en.js', iso: 'en-US' }
      ],
      defaultLocale: 'ru',
      // and some other i18n options
    }]
  ]
}
altynbek07 commented 4 years ago

@NicoPennec Yes, It works. Thank you. I'm closing this issue.