vue-router路由跳转的onComplete、onAbort函数使用方法

本文详细介绍了Vue.js中使用$router.push方法进行路由跳转的语法及回调函数的应用。包括如何通过onComplete回调处理成功的路由跳转,以及如何利用onAbort回调应对路由跳转被终止的情况。
//router.(location, onComplete?, onAbort?)
this.$router.push({
        name:'myRouter',
        params:{
          a:1
        }
      },(to)=>{
        console.log(to'onComplete')
      },(msg)=>{
        console.log(msg,'onAbort')
      })
  1. onComplete
    onComplete为成功跳转后调用,to为跳转到的路由信息如下图:
    在这里插入图片描述

  2. onAbort
    onAbort在跳转路由终止 (导航到相同的路由、或在当前导航完成之前导航到另一个不同的路由) 的时候进行相应的调用,msg参数为跳转的过程描述信息,例如,在beforeRouteEnter中使用next(‘/otherPath’)将路由转换到第三个地址,就会触发onAbort,msg如下图

    在这里插入图片描述
    该信息描述了,从/跳转到/myRouter/1时被重新定向了(并没有说明定向到哪)
    注意:当路由在同一个路径跳转时,也会触发onAbort

localhost/:1 Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist. localhost/:1 Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist. localhost/:1 Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist. localhost/:1 Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist. content.js-c1c147bd.js:1 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'exception') at content.js-c1c147bd.js:1:42224 localhost/:1 Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist. log.js:24 [HMR] Waiting for update signal from WDS... vue-router.esm.js:1841 [Intervention]Slow network is detected. See https://www.chromestatus.com/feature/5636954674692096 for more details. Fallback font will be used while loading: http://localhost/static/fonts/element-icons.535877f5.woff vue.runtime.esm.js:8429 Download the Vue Devtools extension for a better development experience: https://github.com/vuejs/vue-devtools main.js:422 购物党隐私说明(键入disable_gwd_privacy()不再显示本声明): main.js:423 我们不会收集用户个人隐私信息,只会收集一些简单的产品交互行为,帮助改善产品,例如记录某个模块点击次数,更多信息请关注: main.js:424 隐私协议: https://www.gwdang.com/static_page/privacy_policy.html vue-router.esm.js:2008 Uncaught (in promise) Error: Redirected when going from "/login" to "/dashboard" via a navigation guard. at createRouterError (vue-router.esm.js:2008:1) at createNavigationRedirectedError (vue-router.esm.js:1967:1) at eval (vue-router.esm.js:2314:1) at _callee$ (permission.js:45:1)
最新发布
07-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值