Components

<SwitchLocalePathLink>

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

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

当启用 experimental.switchLocalePathLinkSSR 时,这个组件将在服务器端渲染期间正确呈现动态路由参数。

Props

这个组件支持大多数但不是所有为 <NuxtLink> 文档中记录的 props(不支持 tohref),以及下面描述的 props。

PropDescription
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>