Navigating to current location ("/") is not allowed

1、报错分析

Navigating to current location ("/") is not allowed:不允许导航到当前位置(“ /错误”)

在控制台中看到的错误是新的promise api的一部分:在以前,如果没有向router.push提供回调,则错误仅发送到全局路由器错误处理程序,所以在控制台看不到报错;但现在,由于push和replace都返回了一个promise,因此,如果未捕获到导航失败(取消导航的任何事情(如next(false)或next('/ other')也算在内)),因为没有兑现承诺,将在控制台中看到错误

2、造成报错的代码:

使用push对路由进行控制

this.$router.push({ path: '/Solution' })

3、解决方法

在push后面加上catch函数即:

this.$router.push({ path: '/Solution' }).catch(data => {  })

借鉴博客:https://stackoverflow.com/questions/58056675/vuejs-navigating-to-current-location-is-not-allowed

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值