diff --git a/components/g/Nav.vue b/components/g/Nav.vue index 4818df48..eb3a8ad9 100644 --- a/components/g/Nav.vue +++ b/components/g/Nav.vue @@ -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(currentLocale.value); function changeLocale() { diff --git a/composables/useGSwitchLocalePath.ts b/composables/useGSwitchLocalePath.ts new file mode 100644 index 00000000..0f76f1bf --- /dev/null +++ b/composables/useGSwitchLocalePath.ts @@ -0,0 +1,17 @@ +import { + useSwitchLocalePath as _useSwitchLocalePath, + getComposer, +} from 'vue-i18n-routing'; + +/** useSwitchLocalePathのラッパー関数。 */ +export function useGSwitchLocalePath( + options?: NonNullable[0]> +): ReturnType { + const { route, router, i18n, strategy } = options || {} + return _useSwitchLocalePath({ + route: route || useRoute(), + router: router || useRouter(), + i18n: i18n || getComposer(useNuxtApp().$i18n), + strategy: strategy ?? 'prefix', // ←リンクではprefixつきにする + }); +} \ No newline at end of file