如何解决报错:
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/apiWord?id=299".
这个报错主要原因是Vue 重复点击相同路由造成的。不影响功能。
解决方案:
第一种:找到点击跳转的click事件,捕获push的异常即可。添加代码如下
第二种:在router下的index.js文件夹中,重写push,添加代码如下(在use之后添加)
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
//添加以下代码
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
return originalPush.call(this,location).catch(err => err)
}
两种方法都可以使报错不再出现。
如果快乐太难,那祝你平安!