I18n-module: Wrong alternate links

Created on 29 Nov 2020  ·  3Comments  ·  Source: nuxt-community/i18n-module

Version

nuxt-i18n: 6.15.4
nuxt: 2.14.7

Nuxt configuration

mode:

  • [x] universal
  • [ ] spa

Nuxt-i18n configuration

  i18n: {
    locales: [
      { code: 'ru', iso: 'ru-RU', file: 'ru.js', name: 'Русский' },
      { code: 'en', iso: 'en-US', file: 'en.js', name: 'English' },
      { code: 'de', iso: 'de-DE', file: 'de.js', name: 'Deutsch' }
    ],
    defaultLocale: 'ru',
    strategy: 'prefix',
    langDir: 'lang/',
    lazy: true,
    seo: true
  }

Reproduction Link

https://codesandbox.io/s/lively-wave-yqcci?file=/nuxt.config.js

Steps to reproduce

  1. Add some page to extendRoute in nuxt.config.js
  2. Check links in the head

What is Expected?

All links in head(i18n-alt-{lang}, i18n-xd, i18n-can) must have slash on the end, because option trailingSlash:true

What is actually happening?

Pages which added to extendRoute don’t have slash on the end of link

question❓

Most helpful comment

You need to also add this key to your custom routes:

pathToRegexpOptions: {"strict":true},

This is something that Nuxt is adding automatically when using trailingSlash: true but it doesn't change your custom routes.

You can look into .nuxt/router.js to see how your custom routes differ from auto-generated ones.

All 3 comments

I don't think either Nuxt or this module does any processing (or "auto-fixing") for manually added routes through extendRoutes. You need to make sure yourself that the paths of the added routes already include the trailing slash.

All paths in extendRoutes include the trailing slash.

You need to also add this key to your custom routes:

pathToRegexpOptions: {"strict":true},

This is something that Nuxt is adding automatically when using trailingSlash: true but it doesn't change your custom routes.

You can look into .nuxt/router.js to see how your custom routes differ from auto-generated ones.

Was this page helpful?
0 / 5 - 0 ratings