nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.71k stars 478 forks source link

The switchLocalePath method cannot get the incoming language address #2920

Closed rczdgbg closed 5 months ago

rczdgbg commented 5 months ago

Environment

Node Version: v20.11.0 Nuxt Version: 3.11.2 CLI Version: 3.11.2 Nitro Version: 2.9.6 Package Manager: pnpm@9.0.2

Reproduction

https://stackblitz.com/edit/github-a5wazj-tp1y9r?file=pages%2Findex.vue

Describe the bug

defaultLocale:'en' expect: switchLocalePath("en") ---> / switchLocalePath("de") ---> /de result: switchLocalePath("en") ---> / switchLocalePath("de") ---> /

Additional context

No response

Logs

No response

howbizarre commented 5 months ago

I'm having the same problem, but there's one more thing.

My switchLocale component is:

<script setup lang="ts">
import { LanguageIcon } from '@heroicons/vue/24/solid';

const { locale, locales } = useI18n();
const switchLocalePath = useSwitchLocalePath();
const otherAvailableLocales = computed(() => (locales.value).filter(i => i.code !== locale.value));
</script>

<template>
  <NuxtLink v-for="locale in otherAvailableLocales" :key="locale.code" :to="switchLocalePath(locale.code)" class="btn btn-default">
    <LanguageIcon class="btn--icon-left" /> {{ locale.name }}
  </NuxtLink>
</template>

but classes router-link-active and router-link-exact-active are added in the generated code

<a aria-current="page" href="/en" class="router-link-active router-link-exact-active btn btn-default">...</a>

Perhaps this is an effect due to the problem described above?

anick-xs commented 5 months ago

I'm having the same problem too.

rczdgbg commented 5 months ago

image

vue-router 4.3.1 There is a problem 4.3.0 no problem

BobbieGoede commented 5 months ago

@rczdgbg You're right, a change in vue-router@4.3.1 breaks route resolution, possibly https://github.com/vuejs/router/pull/2189.

While we're trying to figure out why this is breaking I recommend overriding the version of vue-router to 4.3.0 in your package.json as a temporary workaround, you can do so by adding the following to your package.json:

  "overrides" {
    "vue-router": "4.3.0"
  }

You may have to remove lockfiles before installing to make this work.

BobbieGoede commented 5 months ago

The breaking change in vue-router@4.3.1 has been reverted and released in vue-router@4.3.2, the workaround can be removed. Simply removing lockfiles and reinstalling dependencies should resolve this issue if you were experiencing it.

Closing this as resolved, if you're still experiencing issues let me know!

xushnudbek20 commented 5 months ago

Still not working. My version: ^8.3.0

BobbieGoede commented 5 months ago

Still not working. My version: ^8.3.0

@xushnudbek20 Have you read the comments in this issue? If you're still experiencing this issue can you open a new issue with a minimal reproduction?