Lzh on GitHub

<SwitchLocalePathLink>

一个用于渲染从 switchLocalePath 解析的路径的增强型受限 <NuxtLink>

此组件是一个受限的 <NuxtLink>,它内部使用 switchLocalePath() 来链接到所提供语言环境中的同一页面。

我们特别推荐在语言切换器中使用此组件,因为它会在服务器端渲染期间正确更新使用动态路由参数的路由。

属性

除了下面描述的属性外,此组件还支持 <NuxtLink> 文档中记录的大部分(但不是所有)属性(不支持 tohref)。

属性描述
locale可选属性,强制使用传入的语言环境进行本地化,默认为当前语言环境。与 switchLocalePath()locale 参数相同

示例

基本用法

<template>
  <SwitchLocalePathLink locale="nl">Dutch</SwitchLocalePathLink>
  <SwitchLocalePathLink locale="en">English</SwitchLocalePathLink>
</template>

<script setup>
const switchLocalePath = useSwitchLocalePath()
</script>

<template>
  <NuxtLink :to="switchLocalePath('nl')">Dutch</NuxtLink>
  <NuxtLink :to="switchLocalePath('en')">English</NuxtLink>
</template>