解决多个路由绑定同一个组件 获取参数只获取一次的方法

{
    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);
        }
      }
    ]
  },

这三个路由绑定的是同一个组件,在javascript

created(){
   console.log(this.$route.params.id)
}

里面这种动做只会执行一次,也就是只能拿到该组件建立时的路由id,
若是要得到不一样的id必须使用官方推荐的方法
响应路由参数的变化html

const User = {
  template: '...',
  watch: {
    '$route' (to, from) {
      // 对路由变化做出响应...
    }
  }
}

或者使用 2.2 中引入的 beforeRouteUpdate 守卫:vue

const User = {
  template: '...',
  beforeRouteUpdate (to, from, next) {
    // react to route changes...
    // don't forget to call next()
  }
}
相关文章
相关标签/搜索