关于vue.js:VueUncaught-in-promise-NavigationDuplicated

45次阅读

共计 715 个字符,预计需要花费 2 分钟才能阅读完成。

vue router 路由反复触发导致的报错

VueUncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/

 或者

vue Uncaught Error: Redirected when going from“/*“to“/*“

废话不多说

办法 1:
https://mp.csdn.net/editor/ht…

这种解决办法能够是能够,然而办法 2 感觉更好些

 this.$router.replace({
        path: this.$route.path,
        query
   })
 .catch(()=>{});// 把 error 抛出来 

办法 2:
倡议认真看看 github 上这个探讨计划 说的很具体  https://github.com/vuejs/vue-…

// 初始化 注入路由中央
import Vue from 'vue'
import Router from 'vue-router'

const originalPush = Router.prototype.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);
};

Vue.use(Router)

...
const router = new Router({routes})

...

正文完
 0