前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >vue路由NavigationDuplicated错误

vue路由NavigationDuplicated错误

作者头像
阿超
发布2022-08-16 17:25:38
3710
发布2022-08-16 17:25:38
举报
文章被收录于专栏:快乐阿超快乐阿超

有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。——蒲松龄

如果遇到了Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location异常

image-20201126195651120
image-20201126195651120

可以在router里配置一下

image-20201126200028440
image-20201126200028440
代码语言:javascript
复制
import Vue from 'vue'
import Router from 'vue-router'

// 解决路由重复问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)

export default new Router({
    mode: 'history',
    routes: [
        {path: '*', redirect: {name: '404'}},
        {path: '/', redirect: {name: 'home'}},
        {path: '/404', name: '404', component: resolve => require(['../views/common/404.vue'], resolve)},
        {path: '/home', name: 'home', component: resolve => require(['../views/sys/home.vue'], resolve)}
    ]
})
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-11-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档