vue报错Navigating to current location ("/login") is not allowed

报错信息

错误原因:出现这个错误的原因是,在路由跳转的时候两次push的path地址相同

最后发现自己在/login页面跳转的时候确实还是跳转到这个页面

解决办法1:将通过路由的<router-link>或者是this.$router.push指向其他的页面。

解决办法2: 如果非要跳转同一个页面可以看下面

import VueRouter from "vue-router";
// 解决两次访问相同路由地址报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

其中location改为自己的页面路径即可

发布了62 篇原创文章 · 获赞 11 · 访问量 8611

猜你喜欢

转载自blog.csdn.net/qq_38588845/article/details/104174516