嵌套路由

This commit is contained in:
theluyuan 2021-05-12 10:10:09 +08:00
parent fcd5b18321
commit f7331951b7
3 changed files with 71 additions and 2 deletions

View File

@ -59,8 +59,8 @@ export default {
// params
console.log(1)
// this.$router.push({path: '/params/123' })
this.$router.push({name:"params",params:{id:123,name:111,aaa:111}})
// this.$router.push("/")
// this.$router.push({name:"params",params:{id:123,name:111,aaa:111}})
this.$router.push("/sitteng/user")
},
replace(){
// 退 ( )

44
src/pages/sitteng.vue Normal file
View File

@ -0,0 +1,44 @@
<template>
<div class="sitteng">
<div class="nav">
<button @click="navto('index')">到index</button>
<button @click="navto('user')">到user</button>
<button @click="navto('admin')">到admin</button>
</div>
<div class="box">
<router-view></router-view>
</div>
</div>
</template>
<style scoped>
.sitteng{
width: 100%;
height: 100vh;
display: flex;
}
.nav{
width: 15%;
height: 100%;
/* background-color: #0f0; */
border-right: 1px solid #bcbcbc;
display: flex;
flex-direction: column;
}
.nav > button {
width: 100%;
}
.box{
width: 85%;
height: 100%;
/* background: #f00; */
}
</style>
<script>
export default {
methods:{
navto(url){
this.$router.push(url)
}
}
}
</script>

View File

@ -14,6 +14,31 @@ const routes = [
next()
}, component: admin
},
{
path:"/sitteng",
component: () => import("../pages/sitteng.vue"),
children:[
{
path:"index",
component: () => import("../views/index.vue"),
meta:123, beforeEnter: (to, from, next) => {
// ...
console.log("路由独享")
next()
}
},
{
path: "user",
component: () => import("../views/user.vue")
},
{
path:"admin",
component: () => import("../pages/admin.vue")
}
]
},
{ path: "/params",meta:"admin", name: "params", component: () => import("../pages/params.vue") } // ()=>import('') 按需加载 路由异步加载
]
// path