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

Redirects not working for translated routes #2939

Open
baijii opened this issue Apr 29, 2024 · 1 comment
Open

Redirects not working for translated routes #2939

baijii opened this issue Apr 29, 2024 · 1 comment

Comments

@baijii
Copy link

baijii commented Apr 29, 2024

Environment

  • Operating System: Darwin
  • Node Version: v20.11.0
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools, modules, i18n
  • Runtime Modules: @nuxtjs/[email protected]
  • Build Modules: -

Reproduction

Reproduction repo: https://github.com/baijii/nuxt_i18n_router_bug

// nuxt.config.ts
export default defineNuxtConfig({
  devtools: { enabled: true },
  modules: ["@nuxtjs/i18n"],
  i18n: {
    locales: [
      { code: 'en', iso: 'en-US', file: 'en.json' },
      { code: 'de', iso: 'de-DE', file: 'de.json' },
    ],
    baseUrl: 'http://localhost:3000',
    defaultLocale: 'en',
    strategy: 'prefix',
    langDir: 'locales/',
    detectBrowserLanguage: {
      useCookie: true,
    }
  }
})

// inside page component
defineI18nRoute({
  paths: {
    en: '/about-us',
    de: '/ueber-uns',
  }
})

Describe the bug

With a German browser (without locale cookie) I navigate to /about-us.

Is:
I get redirected to /en/about-us

Should:
I get redirected to /de/ueber-uns

With a German browser (with locale cookie de) I navigate to /about-us.

Is:
I get a 404 error

Should:
I get redirected to /de/ueber-uns

Additional context

I added some cypress tests, that can executed by firstly starting the server:

npm run dev

and then start the cypress tests

npx cypress run

Logs

No response

@baijii
Copy link
Author

baijii commented Apr 29, 2024

Just tried out at the @nuxtjs/i18n module repo. Also there it's similar. I set my Browser to french, add strategy: 'prefix' in nuxt.config.ts, open http://localhost:3000 and will be redirected to http://localhost:3000/en instead of http://localhost:3000/fr.

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