vue-router.esm.js:2065 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/search/hw".
时间: 2024-06-09 18:06:16 浏览: 199
解决Vue-Router升级导致的Uncaught (in promise)问题
错误信息 "vue-router.esm.js:2065 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/search/hw"" 表明在点击同一个跳转路由时,出现了重复导航的错误。这个错误可以通过重写 `push` 和 `replace` 方法来解决。在目录router的index.js中重写这两个方法,可以处理异常并避免重复导航的错误。
代码示例:
```javascript
let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;
VueRouter.prototype.push = function(location, resolve, reject) {
if (resolve && reject) {
originPush.call(this, location, resolve, reject);
} else {
originPush.call(this, location, () => {}, () => {});
}
}
VueRouter.prototype.replace = function(location, resolve, reject) {
if (resolve && reject) {
originReplace.call(this, location, resolve, reject);
} else {
originReplace.call(this, location, () => {}, () => {});
}
}
```
这样重写之后,再点击同一个跳转路由时就不会再出现重复导航的错误了。
阅读全文