这个组件作为一个受限的 <NuxtLink>
,内部使用 switchLocalePath()
来链接到提供的语言环境中的相同页面。
当启用 experimental.switchLocalePathLinkSSR
时,这个组件将在服务器端渲染期间正确呈现动态路由参数。
这个组件支持大多数但不是所有为 <NuxtLink>
文档中记录的 props(不支持 to
或 href
),以及下面描述的 props。
Prop | Description |
---|---|
locale | 可选属性,用于强制使用传递的语言环境进行本地化,默认为当前语言环境。与 switchLocalePath() 的 locale 参数相同 |
<template>
<SwitchLocalePathLink locale="nl">荷兰语</SwitchLocalePathLink>
<SwitchLocalePathLink locale="en">英语</SwitchLocalePathLink>
</template>
<!-- 相当于 -->
<script setup>
const switchLocalePath = useSwitchLocalePath()
</script>
<template>
<NuxtLink :to="switchLocalePath('nl')">荷兰语</NuxtLink>
<NuxtLink :to="switchLocalePath('en')">英语</NuxtLink>
</template>