zoukankan      html  css  js  c++  java
  • 解决"Uncaught (in promise) Error: Navigation cancelled from "/" to "/login" with a new navigation"报错处理

     Uncaught (in promise) Error: Navigation cancelled from “/” to “/login” with a new navigation.

    这个错误是vue-router内部错误,没有进行catch处理,导致的编程式导航跳转问题,往同一地址跳转时会报错的情况。

    push和replace 都会导致这个情况的发生。

    解决方法如下:

    在路由器中进行配置:router/index.js

    import Vue from 'vue'
    import Router from 'vue-router'
    
    Vue.use(Router)
    // 解决报错
    const originalPush = Router.prototype.push
    const originalReplace = Router.prototype.replace
    // push
    Router.prototype.push = function push (location, onResolve, onReject) {
      if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
      return originalPush.call(this, location).catch(err => err)
    }
    // replace
    Router.prototype.replace = function push (location, onResolve, onReject) {
      if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
      return originalReplace.call(this, location).catch(err => err)
    }
    

    仅在此记录一下遇到的问题和最后的解决办法,亲测可用。

  • 相关阅读:
    利用Python爬取疫情数据并使用可视化工具展示
    接口与多态
    defer 延迟调用
    Spring缓存注解
    SpringAOP
    Mybatis动态SQL语句
    SpringMVC
    Spring Boot入门
    vue中使用JS实现倒计时功能
    springboot使用aop注解在controller层打印请求和响应报文
  • 原文地址:https://www.cnblogs.com/moutudou/p/14240213.html
Copyright © 2011-2022 走看看