首页 > 其他 > 详细

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

时间:2021-05-11 00:56:54      阅读:680      评论:0      收藏:0      [点我收藏+]

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/html/107813784

这种解决方法可以是可以,但是方法2觉得更好些

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

方法2:

建议仔细看看github上这个讨论方案 说的很详细  https://github.com/vuejs/vue-router/issues/2881

//初始化 注入路由地方
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
})

...

 

 
技术分享图片

技术分享图片?

技术分享图片

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

原文:https://www.cnblogs.com/tianmiaogongzuoshi/p/14753045.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!