Repository: nuxt-modules/i18n

Issue #632: trailing slash on localized index page
Created: 2020-03-13T12:21:57Z
I have:

2 locales en and cn(for example)
underscore page(_.vue), for dynamic pages(data from backend).
nuxt-i18n, strategy: "prefix_except_default", defaultLocale: "en".
routes may to be without trailing slash at the end (example.com, example.com/cn)

If I use index.vue, all works as expected, but if I use _.vue, it cannot recognize cn locale
For _.vue works good, only with trailing slash at the end
Version
v6.6.0
Reproduction link
https://codesandbox.io/s/fancy-haze-27wr0
Steps to reproduce

go to /cn (without trailing slash on the end)
get info
you see "en" locale in console

What is expected ?
Go to /cn and get current locale "cn"
Also correct behaviour of switchLocalePath method
What is actually happening?
If you go to /cn, you will get current locale "en"
For now switchLocalePath method goes to "/cn/cn"(Chinese link) and "/cn"(English link) on "/cn" path
Additional comments?
I'm using underscore page (_.vue), because of dynamic data from backend

This bug report is available on Nuxt community (#c416)

Duplicate issue #1378: Incorrect locale when page entered without slash after language slug.
Created: 2022-01-13T17:27:32Z
Version
@nuxtjs/i18n: v7.2.0
nuxt:  v2.15.8
@nuxtjs/i18n configuration
      [
        '@nuxtjs/i18n',
        {
          strategy: 'prefix_except_default',
          detectBrowserLanguage: false,
          baseUrl: 'http://test.local:8080',
          locales: [
            {
              name: 'English',
              code: 'en',
              iso: 'en-GB'
            },
            {
              name: 'Norwegian',
              code: 'nb',
              iso: 'nb-NO'
            }
          ],
         
          vuex: {
            preserveState: true,
            //syncLocale: true https://i18n.nuxtjs.org/migrating
          },
          lazy: false,
          defaultLocale: 'nb',
        }
      ]

What is Expected?
The default locale is NB.
When I enter the page with both url http://test.local:8080/en and http://test.local:8080/en/ I'd like to have  locale EN
What is actually happening?
When I enter the page: http://test.local:8080/en locale is NB
When I enter the page http://test.local:8080/en/ (With slash at the end) Locale is EN
When I enter the page with any deeper link like http://test.local:8080/en/test or http://test.local:8080/en/test/  in both cases locale is set correctly as EN
The only one time with the issue appear is when I enter the home page without slash. I have tried to set router: { trailingSlash: true } But in that case the error is all the way around with slash it is NB without EN, and as previously no issues in deeper url's.
Before I used nuxtjs/i18n 6.6... with Nuxt 2.0.something and It was correct as far as I remember and how it works now.
The only solution that I found is temporary server-middleware to remove or add  (depend of route setting) last slash if user enter home page.
Reproduction
https://codesandbox.io/s/musing-frost-99zbf Just try .../en and .../en/ inside code sandbox. it print out the current locale. I also added simple links to easy click through the issue.

Closing comment (2022-01-14T10:40:21Z): You have a _.vue route in the project which captures the /en path and treats it as a slug en using the default locale NB.
You can have a look at the generated routes in .nuxt/router.js to better understand why it's happening:
  routes: [{
    path: "/en/*",
    component: _f0fe2a6e,
    name: "all___en"
  }, {
    path: "/*",
    component: _f0fe2a6e,
    name: "all___nb"
  }],
Only the second route will catch the /en path.
Also this is a duplicate of #632