<NuxtLinkLocale>
一个使用 localePath 配合 <NuxtLink> 的简写组件
此组件构建于 <NuxtLink> 之上,但通过内部使用 localePath() 来改变默认行为,使其更易于链接到本地化路由。
属性
除了下面描述的属性外,此组件还支持 <NuxtLink> 文档中记录的所有属性。
| 属性 | 描述 |
|---|---|
locale | 可选属性,强制使用传入的语言环境进行本地化,默认为当前语言环境。与 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>