fix switchLocalePath

This commit is contained in:
kakkokari-gtyih 2024-01-21 17:27:49 +09:00
parent eae0677fcd
commit 633c545c7c
2 changed files with 19 additions and 2 deletions

View File

@ -115,7 +115,7 @@ const navOpen = ref(false);
const { locales, locale: currentLocale } = useI18n();
const route = useRoute();
const { afterEach, push } = useRouter();
const { push } = useRouter();
const currentPath = ref(route.path);
watch(() => route.path,(to) => {
@ -124,7 +124,7 @@ watch(() => route.path,(to) => {
immediate: true,
});
const switchLocalePath = useSwitchLocalePath();
const switchLocalePath = useGSwitchLocalePath();
const localePath = useGLocalePath();
const spLocaleOption = ref<string>(currentLocale.value);
function changeLocale() {

View File

@ -0,0 +1,17 @@
import {
useSwitchLocalePath as _useSwitchLocalePath,
getComposer,
} from 'vue-i18n-routing';
/** useSwitchLocalePathのラッパー関数。 */
export function useGSwitchLocalePath(
options?: NonNullable<Parameters<typeof _useSwitchLocalePath>[0]>
): ReturnType<typeof _useSwitchLocalePath> {
const { route, router, i18n, strategy } = options || {}
return _useSwitchLocalePath({
route: route || useRoute(),
router: router || useRouter(),
i18n: i18n || getComposer(useNuxtApp().$i18n),
strategy: strategy ?? 'prefix', // ←リンクではprefixつきにする
});
}