Nuxt i18n
组合式函数

useLocalePath

useLocalePath() 组合函数返回一个根据当前语言环境解析路径的函数。

useLocalePath() 组合函数返回一个根据当前语言环境解析路径的函数。

它始终解析当前域名下的路径,不会考虑哪个域名提供某种语言环境。在启用 differentDomainsmultiDomainLocales 时,对于由其他域名提供的语言环境,它返回的路径在加载 URL 时会重定向到相应域名,因此请使用 useSwitchLocalePath()<SwitchLocalePathLink> 链接到其他语言环境——它们会解析提供该语言环境的域名。

类型

declare function useLocalePath(
  options?: I18nCommonRoutingOptionsWithComposable
): (route: RawLocation | RouteLocation, locale?: Locale) => string

用法

<script setup>
const localePath = useLocalePath()
</script>

<template>
  <NuxtLink :to="localePath('index')">{{ $t('home') }}</NuxtLink>
</template>
Copyright © 2026