Composables
useLocalePath
The useLocalePath() composable returns a function that resolves a path according to the current locale.
The useLocalePath() composable returns a function that resolves a path according to the current locale.
It always resolves a path on the current domain, it doesn't consider which domain serves a locale. Under differentDomains or multiDomainLocales a path it returns for a locale served elsewhere is redirected to that domain when the URL is loaded, so link to another locale with useSwitchLocalePath() or <SwitchLocalePathLink> instead - those resolve the domain serving the locale.
Type
declare function useLocalePath(
options?: I18nCommonRoutingOptionsWithComposable
): (route: RawLocation | RouteLocation, locale?: Locale) => string
Usage
<script setup>
const localePath = useLocalePath()
</script>
<template>
<NuxtLink :to="localePath('index')">{{ $t('home') }}</NuxtLink>
</template>