在 VuePress 中,你可以通过以下几种方式实现页面间的跳转:
最简单的方式是使用标准的 Markdown 链接语法:
[跳转到首页](/)
[跳转到关于页](/about.md)
[跳转到指定标题](/guide/README.md#标题名称)
<router-link>
组件在 VuePress 中,你可以直接使用 Vue Router 的功能:
<router-link to="/">跳转到首页</router-link>
<router-link to="/about/">关于我们</router-link>
在自定义组件或 Vue 文件中,可以使用 this.$router
方法:
methods: {
goToPage() {
this.$router.push('/path/to/page')
}
}
$page
和 $site
对象可以动态生成链接:
当前页面路径: {{ $page.path }}
站点基础路径: {{ $site.base }}
[访问Vue官网](https://vuejs.org/)
在页面的 Frontmatter 中定义 prev
和 next
:
---
prev: /guide/README.md
next: /guide/configuration.md
---
.md
扩展名this.$site
和 this.$page
访问路由信息// .vuepress/config.js
module.exports = {
themeConfig: {
sidebar: [
{
title: '指南',
path: '/guide/',
children: [
'/guide/installation',
'/guide/configuration'
]
}
]
}
}
以上方法可以根据你的具体需求选择使用,VuePress 内置了 Vue Router,因此所有 Vue Router 的功能都可以在 VuePress 中使用。