添加导航和侧边栏
完善的导航系统能帮助用户快速找到所需内容。
导航栏配置
基础导航
ts
// .vitepress/config.mts
export default defineConfig({
themeConfig: {
nav: [
{ text: '首页', link: '/' },
{ text: '指南', link: '/guide/' },
{ text: 'API', link: '/api/' }
]
}
})1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
下拉菜单
ts
nav: [
{ text: '首页', link: '/' },
{
text: '学习',
items: [
{ text: '指南', link: '/guide/' },
{ text: '教程', link: '/tutorial/' },
{ text: 'API', link: '/api/' }
]
}
]1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
多级下拉
ts
nav: [
{
text: '更多',
items: [
{
text: '资源',
items: [
{ text: '视频教程', link: '/videos' },
{ text: '案例展示', link: '/showcase' }
]
},
{ text: '社区', link: '/community/' }
]
}
]1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
带徽章的导航
ts
nav: [
{
text: '新功能',
link: '/new-features',
badge: { text: '新', type: 'tip' }
}
]1
2
3
4
5
6
7
2
3
4
5
6
7
外部链接
ts
nav: [
{ text: 'GitHub', link: 'https://github.com', target: '_blank' }
]1
2
3
2
3
侧边栏配置
基础侧边栏
ts
export default defineConfig({
themeConfig: {
sidebar: [
{
text: '开始',
items: [
{ text: '介绍', link: '/guide/' },
{ text: '安装', link: '/guide/installation' }
]
},
{
text: '基础',
items: [
{ text: 'Markdown', link: '/basics/markdown' },
{ text: '配置', link: '/basics/config' }
]
}
]
}
})1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
多侧边栏
根据不同路径显示不同侧边栏:
ts
sidebar: {
'/guide/': [
{
text: '指南',
items: [
{ text: '介绍', link: '/guide/' },
{ text: '安装', link: '/guide/installation' }
]
}
],
'/api/': [
{
text: 'API 参考',
items: [
{ text: '配置', link: '/api/config' },
{ text: '运行时', link: '/api/runtime' }
]
}
]
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
折叠分组
ts
sidebar: [
{
text: '进阶',
collapsed: true, // 默认折叠
items: [
{ text: '插件', link: '/advanced/plugins' },
{ text: '主题', link: '/advanced/themes' }
]
}
]1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
嵌套侧边栏
ts
sidebar: [
{
text: '教程',
items: [
{
text: '入门',
collapsed: true,
items: [
{ text: '快速开始', link: '/tutorial/quick-start' },
{ text: '目录结构', link: '/tutorial/structure' }
]
},
{
text: '进阶',
collapsed: true,
items: [
{ text: '自定义主题', link: '/tutorial/custom-theme' },
{ text: '插件开发', link: '/tutorial/plugin-dev' }
]
}
]
}
]1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
带徽章的侧边栏
ts
sidebar: [
{
text: '指南',
items: [
{
text: '新功能',
link: '/guide/new',
badge: { text: '新', type: 'tip' }
}
]
}
]1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
社交链接
ts
export default defineConfig({
themeConfig: {
socialLinks: [
{ icon: 'github', link: 'https://github.com/...' },
{ icon: 'twitter', link: 'https://twitter.com/...' },
{ icon: 'discord', link: 'https://discord.gg/...' }
]
}
})1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
完整示例
ts
// .vitepress/config.mts
import { defineConfig } from 'vitepress'
export default defineConfig({
title: '我的文档',
description: 'VitePress 站点',
themeConfig: {
// Logo
logo: '/logo.svg',
// 站点标题
siteTitle: '我的文档',
// 导航栏
nav: [
{ text: '首页', link: '/' },
{
text: '指南',
activeMatch: '/guide/',
items: [
{ text: '介绍', link: '/guide/' },
{ text: '快速开始', link: '/guide/quick-start' },
{ text: '安装', link: '/guide/installation' }
]
},
{
text: 'API',
link: '/api/',
badge: { text: '完整', type: 'tip' }
},
{ text: 'GitHub', link: 'https://github.com', target: '_blank' }
],
// 侧边栏
sidebar: {
'/guide/': [
{
text: '开始',
items: [
{ text: '介绍', link: '/guide/' },
{ text: '快速开始', link: '/guide/quick-start' }
]
},
{
text: '基础',
collapsed: false,
items: [
{ text: 'Markdown', link: '/guide/markdown' },
{ text: '配置', link: '/guide/configuration' }
]
},
{
text: '进阶',
collapsed: true,
items: [
{ text: '主题', link: '/guide/themes' },
{ text: '插件', link: '/guide/plugins' }
]
}
],
'/api/': [
{
text: 'API 参考',
items: [
{ text: '配置 API', link: '/api/config' },
{ text: '运行时 API', link: '/api/runtime' }
]
}
]
},
// 社交链接
socialLinks: [
{ icon: 'github', link: 'https://github.com/...' }
]
}
})1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
学习检查清单
- [ ] 配置了导航栏
- [ ] 添加了下拉菜单
- [ ] 配置了侧边栏
- [ ] 实现了多侧边栏
- [ ] 添加了社交链接
下一步
继续学习 部署到线上,发布你的站点。