解决同一路由,不同参数报Navigating to current location ***** is not allowed 问题

在某个详情页中(当前路由已为/RecycleDeta),需要跳转另外一个同类型链接,跳转代码

this.$router.push({path:'/RecycleDeta',query:{demandId}})

报错

面向百度编程了解了下,有的说需要重写ruter.push方法,我嫌麻烦,所以修改如下

this.$router.push({path:'/RecycleDeta',query:{demandId}}).catch(err => {});

 这回没报错了,但是页面没有根据不同参数刷新页面。再使用路由监听beforeRouteUpdate或watch方法监听路由变化

方法一:

  beforeRouteUpdate(to, from, next){
    debugger
    next();
    // 查询数据
    this.handleDetail();
    this.getDemandFile();
  },

 或方法二

 watch:{
   '$route':{
     handler(to) {
       // to:目标路由对象
       debugger
       this.handleDetail();
       this.getDemandFile();
     }
   }
 }

如此,跳转同一路由不同参数完美解决。

你可能感兴趣的:(vue)