vue报错:name: "NavigationDuplicated",message: "Navigating to current location ("/pool") is not allowed

vue报错:name: “NavigationDuplicated”,message: “Navigating to current location (”/pool") is not allowed

vue报错:name:

这句话的意思:在路由跳转的时候不允许两次push/replace的path地址相同

解决方法:

  • 方法一: vue-router 回退版本3.0 (3.1以下版本)
npm uninstall vue-router    
npm install [email protected] -S
  • 方法二: 对路由的push和replace方法重写规则
import VueRouter from "vue-router";

const [routerPush, routerReplace] = [VueRouter.prototype.push, VueRouter.prototype.replace];
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error);
};
VueRouter.prototype.replace = function replace(location) {
  return routerReplace.call(this, location).catch(error => error);
};
 

结语:这样再次点击的时候就不会报错了

你可能感兴趣的:(vue)