question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No language redirect with dev with `prefix` strategy in 'spa' mode

See original GitHub issue

Version

nuxt-i18n: 6.9.2 nuxt: 2.0.0

Reproduction Link

https://github.com/dokterbob/i18nuxt-redirect-bug

Steps to reproduce

  1. Clean nuxt project with i18-nuxt configured with strategy set to `prefix’ as per documentation (refer to reproduction link)
  2. Run dev server with npm run dev
  3. Open http://localhost:3000/

What is Expected?

A redirect to a language prefix (/en/ or /pt/).

What is actually happening?

Page not found: “This page could not be found”

Notes

  1. The following settings are sufficient to replicate the problem:
  modules: [
    [
      'nuxt-i18n',
      {
        locales: ['en', 'pt'],
        defaultLocale: 'en',
        strategy: 'prefix',
        vueI18n: {
          fallbackLocale: 'en'
        }
      }
    ]
  ],
  1. The following settings have not shown to solve the problem:
        detectBrowserLanguage: {
          // This doesn't make a difference
          useCookie: false,
          alwaysRedirect: true
        },
  1. The problem also occurs in a production environment with npm run build && npm run start

  2. When using rootRedirect, the browser is redirected to the unprefixed route.

  3. When requesting a route different from the default (e.g. /about/) redirection is also not performed.

  4. Great care has been taken that browser cookies have been cleared in the tests above.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12

github_iconTop GitHub Comments

3reactions
rchlcommented, Apr 23, 2020

Relevant Nuxt issue: https://github.com/nuxt/nuxt.js/issues/4491

I will try to address the Nuxt issue (with a workaround) and the inconsistency in nuxt-i18n handling at the same time.

3reactions
Bigdragon13thcommented, Apr 23, 2020

I also having this issue, but in a weird way. So I think I’ll share my issue, in case it might help fixing this.

I created a new installation of Nuxt and Nuxt-i18n, got the following version: nuxt: 2.12.2 nuxt-i18n: 6.9.3

My browser locale is en-us. My Nuxt mode setting is universal.

This is my nuxt-i18n settings:

i18n: {
  locales: [
    {
      code: 'en',
      name: 'English',
      file: 'en.json',
    },
    {
      code: 'th',
      name: 'ภาษาไทย',
      file: 'th.json',
    },
  ],
  defaultLocale: 'th',
  strategy: 'prefix',
  lazy: true,
  langDir: 'locales/',
  detectBrowserLanguage: {
    useCookie: true,
    alwaysRedirect: true,
  },
},
  • Now, when I try to access http://localhost:3000/, it redirect me to http://localhost:3000/en (I assume it’s because of my browser’s language). Which is expected. I also try remove /en and hit enter again, it’s still works fine.
  • The weird issue came after I switch the language to th (by using switchLocalePath(locale.code)). It redirect me to http://localhost:3000/th, after I remove /th part, I got 404.
  • A more weirder issue. After trying to figure out what’s wrong with my config, I’ve tried changed my defaultLocale to en, now everything broke. Accessing http://localhost:3000/ just throw me 404, it’s not redirect anymore.

My workaround right now is, completely disable detectBrowserLanguage and force rootRedirect. It’s not ideal, but at least it seems working.

rootRedirect: 'th',
detectBrowserLanguage: false,
Read more comments on GitHub >

github_iconTop Results From Across the Web

No language redirect with dev with `prefix` strategy in 'spa' mode
Clean nuxt project with i18-nuxt configured with strategy set to `prefix' as per documentation (refer to reproduction link) · Run dev server with ......
Read more >
Redirect to locale with Nuxtjs and i18n on SPA mode
I got an idea to solve this problem but I did not know if it is the best solution. Just using .htaccess to...
Read more >
Redirection when using a language prefix path - Drupal
Hi, A robots.txt file is supposed to be at the root of the website for example: https://example.com/robots.txt But when you use a language...
Read more >
Sign users in to your SPA using the redirect model | Okta ...
Enter the Sign-in redirect URIs for both local development, such as http://localhost:xxxx/login/callback , and for production, such as https://app.example.com/ ...
Read more >
Vue i18n: Building a multi-language app with locale switcher
Vue i18n is a key process needed to localize your Vue apps and websites. Learn how to set up a Vue app with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found