VUE-Router之解决 Navigating to current location (XXX) is not allowed
Router之解决 Navigating to current location ("/index/list2") is not allowed错误代码:NavigationDuplicated {_name: "NavigationDuplicated",name: "NavigationDuplicated",message: "Navigating to current location (
·
VUE-Router之解决 Navigating to current location ("/index/list2") is not allowed
错误代码:
NavigationDuplicated {
_name: "NavigationDuplicated",
name: "NavigationDuplicated",
message: "Navigating to current location ("/index/list2") is not allowed",
stack: "Error↵ at new NavigationDuplicated (webpack-int…al:///./node_modules/vue/dist/vue.esm.js:1862:26)"
}
操作:
在vue项目中点击两次路由切换
原因:
多次点击跳转同一个路由是不被允许的
解决方案(两种):
1.降低版本:切换版本回3.0版本
2.重写规则:在你引了vue-router的js文件里加上如下代码即可(我的在index.js文件)
import Vue from 'vue' //如果已引用,不需要重复引用
import Router from 'vue-router'; //如果已引用,不需要重复引用
Vue.use(Router) //如果已引用,不需要重复引用
//push
const VueRouterPush = Router.prototype.push
Router.prototype.push = function push (to) {
return VueRouterPush.call(this, to).catch(err => err)
}
//replace
const VueRouterReplace = Router.prototype.replace
Router.prototype.replace = function replace (to) {
return VueRouterReplace.call(this, to).catch(err => err)
}
打赏
谢谢对小女子的关注,我会坚持更新我所遇到的bug及解决方案。要觉得小女子写得还行,可以打赏些小费的哟~
更多推荐
已为社区贡献3条内容
所有评论(0)