嵌套路由
# 代码实现
// router.js
import HomePage from "./pages/HomePage.vue";
import AboutMe from "./pages/AboutMe.vue";
import WorkExperience from "./pages/about/WorkExperience.vue";
import EducationExperience from "./pages/about/EducationExperience.vue";
import { createRouter, createWebHistory } from "vue-router";
const routes = [
{
path: "/",
component: HomePage,
},
{
path: "/about",
component: AboutMe,
children: [
{ path: "work", component: WorkExperience },
{ path: "education", component: EducationExperience },
],
},
];
const router = createRouter({
history: createWebHistory(),
routes,
});
export default router;
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
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
<!-- AboutMe.vue -->
<template>
<div class="container">
<p>Hi 你好!这是关于我的页面</p>
<p>更多详情查看:</p>
<nav>
<router-link to="/about/work">工作经历</router-link>
<router-link to="/about/education">教育经历</router-link>
</nav>
<router-view></router-view>
</div>
</template>
<script>
export default {};
</script>
<style scoped>
.container {
width: 100vw;
height: 100vh;
max-width: 100%;
padding: 24px;
background-color: hsl(280deg, 50%, 20%);
}
p {
margin: 12px 0;
}
nav {
padding-top: 16px;
}
</style>
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
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
编辑 (opens new window)
上次更新: 2023/04/01, 15:26:22