vue-router

解决vue-router报NavigationDuplicated: Avoided redundant navigation to current location 的问题

拜拜、爱过 提交于 2020-09-26 13:56:38
最近写项目的时候, 重复点击路由会在控制台报 这样的错误。 它的提示是 避免到当前位置的冗余导航。 简单来说就是重复触发了同一个路由。 这个错误是 vur-router更新以后新出现的错误。(我使用的是 vue-router 3.2.0)出现的 但是 (vue-router 3.0.6) 没有出现。 但是也不排除是我的 3.0.6之前做过配置。 解决这个错误也非常简单。只需要在router /index的页面里面 加入 const originalPush = VueRouter . prototype . push VueRouter . prototype . push = function push ( location ) { return originalPush . call ( this , location ) . catch ( err => err ) } 这行代码就可以了 他的位置大概在这里 来源: oschina 链接: https://my.oschina.net/u/4390738/blog/4547080