同样直接上代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<body>
<div id="app">
<p>
<router-link to="/user/foo">/user/foo</router-link>
<router-link to="/user/boo">/user/foo</router-link>
</p>
<router-view></router-view>
</div>
<script type="text/javascript">
const UserFoo = {
template:`<h2>{{$route.params.id}}</h2>`
}
const UserBoo = {
template:`<h2>{{$route.params.id}}</h2>`
}
const router = new VueRouter({
routes:[
{
path:'/user/:id',
component:UserFoo,
},{
path:'/user/:id',
component:UserBoo
}
]
})
const app = new Vue({
router
}).$mount('#app')
</script>
</body>
</html>