I18n-module: The first time you enter the URL page of the specified language, nuxt-i18n triggers HTTP status code 302

Created on 30 Nov 2020  ·  6Comments  ·  Source: nuxt-community/i18n-module

Version

nuxt-i18n: ^6.15.4
nuxt: ^2.14.6

Nuxt configuration

mode:

  • [X] universal
  • [] spa

Nuxt-i18n configuration

i18n: {
   locales: [{
        code: 'en',
        iso: 'en-US',
        name: 'English'
    },
    {
        code: 'zh',
        iso: 'zh-ZH',
        name: '中文'
    }
    ],
    defaultLocale: 'zh',
    vueI18n: {
        fallbackLocale: 'zh',
        messages: {
            en: Object.assign(langEn, require('./lang/en')),
            zh: Object.assign(langZhCN, require('./lang/zh'))
        }
    }
}

When I enter the page for the first time, I assume that the address I visited is http://localhost:3000/en/demo
nuxt-i18n It will trigger automatically HTTP status code 302 Get to this page http://localhost:3000/demo
This page is my default language page;
I found that it might be cookie Among them i18n_redirected problem,If i18n_redirected exists, I will be able to access normally. If not, 302 will be triggered

bug 🐛 question❓

Most helpful comment

Try enabling onlyOnRoot option in detectBrowserLanguage https://i18n.nuxtjs.org/options-reference#detectbrowserlanguage .

It will become enabled by-default in the future but for now, it's recommended to set it manually.

This is so cool, it seems to solve my problem perfectly, thank you very much

All 6 comments

I don't know whether this is a bug or a configuration problem. I hope someone can help me. This problem has bothered me for a long time

detectBrowserLanguage is enabled by default so it will redirect to your browser-preferred language. What settings do you use for preferred-language in your browser?

For example, in chrome it looks like this:
Screenshot 2020-11-30 at 09 39 25

detectBrowserLanguage is enabled by default so it will redirect to your browser-preferred language. What settings do you use for preferred-language in your browser?

detectBrowserLanguage 默认是启用的,因此它将重定向到您的浏览器首选语言。浏览器中的首选语言使用什么设置?

For example, in chrome it looks like this:
Screenshot 2020-11-30 at 09 39 25

例如,在 chrome 浏览器中,它看起来像这样:

I found that my default language is Chinese

However, when users copy the fixed URL into the project, they should first use the language carried by the URL. Can this idea be implemented

Try enabling onlyOnRoot option in detectBrowserLanguage https://i18n.nuxtjs.org/options-reference#detectbrowserlanguage .

It will become enabled by-default in the future but for now, it's recommended to set it manually.

Try enabling onlyOnRoot option in detectBrowserLanguage https://i18n.nuxtjs.org/options-reference#detectbrowserlanguage .

It will become enabled by-default in the future but for now, it's recommended to set it manually.

This is so cool, it seems to solve my problem perfectly, thank you very much

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonalxh picture jonalxh  ·  15Comments

javialon26 picture javialon26  ·  20Comments

varna picture varna  ·  14Comments

lucassith picture lucassith  ·  28Comments

pi0 picture pi0  ·  18Comments