该组件基于 <NuxtLink>
构建,但通过内部使用 localePath()
更改了默认行为,以便更轻松地链接到本地化路由。
除了下面描述的 props,该组件还支持所有 为 <NuxtLink>
文档记录的 props。
Prop | 描述 |
---|---|
locale | 可选 prop,强制使用传入的语言环境进行本地化,默认为当前语言环境。与 localePath() 的 locale 参数相同 |
<template>
<NuxtLinkLocale to="/">{{ $t('home') }}</NuxtLinkLocale>
</template>
<!-- 等效于 -->
<script setup>
const localePath = useLocalePath()
</script>
<template>
<NuxtLink :to="localePath('/')">{{ $t('home') }}</NuxtLink>
</template>
<template>
<NuxtLinkLocale to="/" locale="nl">{{ $t('home') }}</NuxtLinkLocale>
</template>
<!-- 等效于 -->
<script setup>
const localePath = useLocalePath()
</script>
<template>
<NuxtLink :to="localePath('/', 'nl')">{{ $t('home') }}</NuxtLink>
</template>