组件

<SwitchLocalePathLink>

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

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

启用 experimental.switchLocalePathLinkSSR 后,此组件将在服务器端渲染期间正确渲染动态路由参数。

属性

此组件支持大多数但不是所有 对应 <NuxtLink> 文档中的属性(不支持 tohref),以及下面描述的属性。

属性描述
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>