No language redirect with dev with `prefix` strategy in 'spa' mode
See original GitHub issueVersion
nuxt-i18n: 6.9.2 nuxt: 2.0.0
Reproduction Link
https://github.com/dokterbob/i18nuxt-redirect-bug
Steps to reproduce
- Clean nuxt project with
i18-nuxt
configured withstrategy
set to `prefix’ as per documentation (refer to reproduction link) - Run dev server with
npm run dev
- 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
- The following settings are sufficient to replicate the problem:
modules: [
[
'nuxt-i18n',
{
locales: ['en', 'pt'],
defaultLocale: 'en',
strategy: 'prefix',
vueI18n: {
fallbackLocale: 'en'
}
}
]
],
- The following settings have not shown to solve the problem:
detectBrowserLanguage: {
// This doesn't make a difference
useCookie: false,
alwaysRedirect: true
},
-
The problem also occurs in a production environment with
npm run build && npm run start
-
When using
rootRedirect
, the browser is redirected to the unprefixed route. -
When requesting a route different from the default (e.g.
/about/
) redirection is also not performed. -
Great care has been taken that browser cookies have been cleared in the tests above.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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:
http://localhost:3000/
, it redirect me tohttp://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.th
(by usingswitchLocalePath(locale.code)
). It redirect me tohttp://localhost:3000/th
, after I remove/th
part, I got 404.defaultLocale
toen
, now everything broke. Accessinghttp://localhost:3000/
just throw me 404, it’s not redirect anymore.My workaround right now is, completely disable
detectBrowserLanguage
and forcerootRedirect
. It’s not ideal, but at least it seems working.