{
path: '/application',
title: '我的工作',
icon:'code-working',
name: 'application',
component: Main,
children: [
{
path: 'index/:id', title: '我的申请', name: 'myApplication', component: resolve => {
require(['@/views/application/index'], resolve);
}
},
{
path: 'index/:id', title: '我的待办', name: 'have not done', component: resolve => {
require(['@/views/application/index'], resolve);
}
},
{
path: 'index/:id', title: '我的已办', name: 'have been done', component: resolve => {
require(['@/views/application/index'], resolve);
}
}
]
},
这三个路由绑定的是同一个组件,在
created(){
console.log(this.$route.params.id)
}
里面这种动作只会执行一次,也就是只能拿到该组件创建时的路由id,
如果要获得不同的id必须使用官方推荐的方法
响应路由参数的变化
const User = {
template: '...',
watch: {
'$route' (to, from) {
// 对路由变化作出响应...
}
}
}
或者使用 2.2 中引入的 beforeRouteUpdate 守卫:
const User = {
template: '...',
beforeRouteUpdate (to, from, next) {
// react to route changes...
// don't forget to call next()
}
}