vue-router 报错:Navigation cancelled from“/...“ to “/...“ with a new navigation.的3个解决方案
[email protected]版本及以上回调形式已经改成promise api的形式了,返回的是一个promise,如果路由地址跳转相同, 且没有捕获到错误,控制台始终会出现如图所示的警告 (注:3.0以下版本则不会出现以下警告!!!,因路由回调问题…)
怎么解决呢?
方案一:
安装vue-router3.0以下版本:先卸载3.0以上版本然后再安装旧版本 npm install [email protected] -S
方案二:
针对于路由跳转相同的地址添加catch捕获一下异常:this.$router.push(’/location’).catch(err => { console.log(err) })
方案三:
在main.js下注册一个全局函数即可 (注:此处理方案只针对于vue-router 3.0以上版本哈!!!)
import Router from 'vue-router' const originalPush = Router.prototype.push Router.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err) } 注:官方[email protected]及以上新版本路由默认回调返回的都是promise,原先就版本的路由回调将废弃!!!! >
本文属原创,转载请注明原文:http://www.zhimatong.com/jiaocheng/668.html
为保证教程的实用性及扩大知识面覆盖,如果您有相似问题而未解决,可联系在线客服免费技术支持。
热门主题
相关阅读
- PbootCMS网站常见报错/错误提示及解决方法集合(持续更新)
- ThinkPHP页面提示Warning: require(): open_basedir restriction in effect. File的解决方法
- 解决网站JQ提示"Failed to load resource: the server responded with a status of 404 (Not Found)"的问题
- tp5.1页面报错打不开报警
- vuejs和thinkphp结合的2种方法
- Thinkphp模板输出JSON数据用于VUE
- PbootCMS提示URL名称与模型URL名称冲突,请换一个名称!的解决方法
- 检测到您模板中包含文件超过50个,请检查是否存在互相包含导致无限循环的情况!