Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detectBrowserLanguage and alwaysRedirect unclear routing logic #3048

Open
spiritius opened this issue Aug 1, 2024 · 0 comments
Open

detectBrowserLanguage and alwaysRedirect unclear routing logic #3048

spiritius opened this issue Aug 1, 2024 · 0 comments

Comments

@spiritius
Copy link

Environment

- Operating System: Darwin
- Node Version:     v22.3.0
- Nuxt Version:     3.12.4
- CLI Version:      3.12.0
- Nitro Version:    2.9.7
- Package Manager:  [email protected]
- Builder:          -
- User Config:      compatibilityDate, runtimeConfig, srcDir, dir, app, css, modules, i18n, vite
- Runtime Modules:  @nuxtjs/[email protected], @nuxtjs/[email protected]
- Build Modules:    -

Reproduction

Describe the bug

Hi!

When using the prefix_and_default strategy and the detectBrowserLanguage option, the redirect logic is unclear.

Current behavior:

site.com/ → click NLsite.com/nl → change url manually to site.com/ → get site.com/nl

What I expected from the parameter alwaysRedirect: false:

site.com/ → click NLsite.com/nl → change url manually to site.com/ → get site.com/

Am I doing something wrong? Is there any way to fix this in nuxt.config.ts?

Additional context

// nuxt.config.ts
i18n: {
  vueI18n: '~/app/i18n/i18n.config.ts',
  baseUrl: process.env.BASE_URL,
  locales: [
    { code: 'en', iso: 'en-US', name: 'English' },
    { code: 'nl', iso: 'nl-NL', name: 'Nederlands' }
  ],
  defaultLocale: 'en',
  strategy: 'prefix_and_default',
  detectBrowserLanguage: {
    fallbackLocale: 'en',
    useCookie: true,
    cookieKey: 'lang',
    alwaysRedirect: false,
    redirectOn: 'all'
  }
}

// i18n.config.ts
import en from './locales/en.json'
import nl from './locales/nl.json'

export default defineI18nConfig(() => ({
  legacy: false,
  locale: 'en',
  fallbackLocale: 'en',
  globalInjection: true,
  messages: {
    en,
    nl
  },
  missingWarn: false, 
  fallbackWarn: false,
}))

Logs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant