VUE-子路由
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue-router子路由</title>
</head>
<body>
<div id="app">
<div>
<router-link to="/">首页</router-link>
<router-link to="/about">关于我们</router-link>
<router-link to="/user/王花花">王花花</router-link>
<router-link to="/user/李栓蛋?age=100">李栓蛋</router-link>
</div>
<div>
<router-view></router-view>
</div>
</div>
<script src="https://cdn.bootcss.com/vue/2.6.11/vue.js"></script>
<script src="https://cdn.bootcss.com/vue-router/2.7.0/vue-router.js"></script>
<script src="index.js"></script>
</body>
</html>
JS
var routes = [{
path: '/',
component: {
template: '<div><h1>首页</h1></div>'
},
},
{
path: '/about',
component: {
template: '<div><h1>关于我们</h1></div>'
}
}, {
path: '/user/:name',
component: {
template: '<div><div><h1>我叫:{{$route.params.name}}</h1></div><router-link to="more" append>更多信息</router-link><router-view></router-view></div>'
},
children: [{
path: 'more',
component: {
template: '<div>用户:{{$route.params.name}}的详细信息 信息信息信息信息信息信息信息信息信息</div>'
}
}]
},
]
var router = new VueRouter({
routes: routes
})
new Vue({
el: '#app',
router: router,
})