在 VuePress 中,你可以通过以下几种方式实现页面间的章节跳转:
[跳转到目标章节](./other-page.md#section-id)
其中:
- ./other-page.md
是目标页面的相对路径
- #section-id
是目标页面的章节ID
<a href="./other-page.html#section-id">跳转到目标章节</a>
VuePress 会自动为所有标题生成ID,规则如下:
- 一级标题:#标题
→ #标题
- 二级标题:## 子标题
→ #子标题
- 特殊字符会被转换为连字符,空格转为-
例如:
## 安装指南
生成的ID为 #安装指南
,可以使用 [链接](#安装指南)
跳转
你可以手动指定标题的ID:
## 自定义标题 {#custom-id}
然后使用 [链接](#custom-id)
跳转
假设你有以下结构:
docs/
guide/
getting-started.md
configuration.md
在 getting-started.md
中跳转到 configuration.md
的某个章节:
[查看配置选项](../guide/configuration.md#基本配置)
在 Vue 组件中:
this.$router.push('/path/to/page#section-id')
.md
或 .html
)通过以上方法,你可以灵活地在 VuePress 文档中实现页面间的章节跳转功能。