vue-router.esm.js?8c4f:2065 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “/home”. at createRouterError (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:2066:15) at createNavigationDuplicatedError (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:2036:15) at HTML5History.confirmTransition (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:2329:18) at HTML5History.transitionTo (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:2261:8) at HTML5History.push (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:2602:10) at eval (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:3027:22) at new Promise () at VueRouter.push (webpack-internal:///./node_modules/vue-router/dist/vue-router.esm.js:3026:12) at VueComponent.indexbtnClick (webpack-internal:///./node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/App.vue?vue&type=script&lang=js&:19:20) at invokeWithErrorHandling (webpack-internal:///./node_modules/vue/dist/vue.runtime.esm.js:1862:26)
解决方案1:
捕获异常
this.$router.push('/home').catch(err => console.log(err))
也可以不打印错误信息
this.$router.push('/home').catch(err => {})
解决方案2:
在跳转时,判断路由和当前路由是否一致,如果不一致再跳转 注意:this.$route.path可以获取到当前的路由路径(不是$.router)
if (this.$route.path != '/home') {
this.$router.push('/home')
}
解决方案3:
在src–>router–>index.js添加代码:
const router = new VueRouter({
routes,
mode: 'history',
linkActiveClass: 'active'
})
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
return VueRouterPush.call(this, to).catch(err => err)
}
vue-router官网地址:https://router.vuejs.org/zh/
|