需求:

登陆之后才能查看主页面,否则跳转至登录页

遇到的问题:

一开始是打算直接在拦截器跳转路由的,发现会报错Avoided redundant navigation to current location: "/login".

后来灵机一动,用了全局路由守卫,完美解决

request.interceptors.request.use(config=>{config.headers['Content-Type']='application/json;charset=utf-8'let user=localStorage.getItem("user")if(!user){router.push("/login")}return config
},error=> {return Promise.reject(error)
})

报错:

解决方案:

添加全局路由守卫,并通过localStorage存储信息

全局路由守卫:

router.beforeEach((to,from,next)=>{let user = localStorage.getItem("user");if(!user){if(to.path!=='/login'){next({path:"/login"})}else{next()}}else{next()}
})

登录界面的逻辑判断:

         request.post("/user/login",this.form).then(res=>{if(res.code==='0'){this.$message({type:"success",message:"登录成功"})localStorage.setItem("user",JSON.stringify(res.data))this.$router.push("/")}else{this.$message({type:"error",message:res.msg})}})

报错:Avoided redundant navigation to current location: “/login“.完美解决相关推荐

  1. vue报错 Avoided redundant navigation to current location: “/search“

    报错信息: Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: ...

  2. Vue组件多次点击报错Avoided redundant navigation to current location: “/profile“.

    报错提示profile组件避免了到当前位置的冗余导航. 在VueRouter后添加 const originalPush = VueRouter.prototype.push VueRouter.pr ...

  3. 解决vue-router报NavigationDuplicated: Avoided redundant navigation to current location: “/login“ 的问题

    一.普遍问题解决方法 import Router from 'vue-router'; Vue.use(Router); // 解决ElementUI导航栏中的vue-router在3.0版本以上重复 ...

  4. vue-router 报错Error: Avoided redundant navigation to current location: “/index/user“解决方式

    问题 使用ivew Menu 制作的导航菜单,连续点击同一个导航时报错 该报错不影响功能 当前地址 http://localhost:8080/#/transfer/index 连续点击–信息录入 报 ...

  5. Vue路由跳转报错Avoided redundant navigation to current location: “/xxxxxx“.

    在使用this.$router.push进行路由的跳转时,出现如下报错: 今天在开发的过程遇到了上述问题,通过查阅资料得到了解答,以自己的理解进行了整理 报错原因: 当我们在使用编程式路由进行页面跳转 ...

  6. 解决Vue报错:Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location

    问题描述:重复点击导航时,控制台出现报错 ,虽然不影响功能使用,但也不能坐视不管. 解决 Vue 重复点击相同路由,出现 Uncaught (in promise) NavigationDuplica ...

  7. 解决报错:Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “

    报错内容: vue-router.esm.js?68cf:2065 Uncaught (in promise) NavigationDuplicated: Avoided redundant navi ...

  8. 四种解决Vue中重复点击相同路由控制台报错问题( Avoided redundant navigation to current location)

    vue-router 升级到3.1.x 后,重复点击导航时,控制台出现报错 ,虽然不影响功能使用,但是看的就不舒服. 报错信息 Uncaught (in promise) NavigationDupl ...

  9. 前端开发:Vue项目报错NavigationDuplicated:Avoided redundant navigation to current location:“/XXX”的解决方法

    最近在Vue项目开发的过程中遇到一个问题,那就是在点击同一个路由操作的时候,控制台会报一下错误提示: Uncaught (in promise) NavigationDuplicated: Avoid ...

最新文章

  1. 科大讯飞市值腰斩背后,AI产业集体思考如何落地?
  2. NLP技术在海外金融机构的应用
  3. React.js入门笔记
  4. web移动开发最佳实践之js篇
  5. python按日期排序_python按修改时间顺序排列文件的实例代码
  6. 调用webservice 设置超时时间
  7. python中pygal_在Python中导入pygal查看直方图
  8. python中headers的作用_爬虫入门到精通-headers的详细讲解(模拟登录知乎)
  9. Anagram Groups(字符串)
  10. 什么是 “动态规划” , 用两个经典问题举例。
  11. linux内核分析与应用 -- 并发(下)
  12. PASCAL VOC2012数据集内容解读
  13. PTES执行内容思维导图
  14. 从零开始学Python【23】--线性回归诊断(第二部分)
  15. [生存志] 第39节 郑伯克段于鄢
  16. macos 虚拟镜像文件_如何在macOS中使用虚拟文件测试网络或硬盘速度
  17. catia高级拔模_解读CATIA拔模的秘密
  18. 高斯消去、列主元消去、Lu分解、追赶法(matlab)
  19. Sea.js 使用总结(1)
  20. PLS-00402: 要求在游标的 SELECT 列表中具有别名, 以避免列名重复

热门文章

  1. Android Loader LoaderManager 总结(一)
  2. python一行代码制作简易二维码
  3. Context-Transformer 迁移学习 few-shot目标混淆问题
  4. 亚马逊跟卖出单玩法技巧
  5. Wireshrk 3.0.0网络抓包工具安装及使用(图文教程)
  6. 欢聚时代YY招聘 | 遇见offer之就要圆你的大厂梦
  7. iOS学习之Map,定位,标记位置的使用
  8. c语言和java哪个有前途_学java和c哪个前景好?
  9. 使用Flash Builder 4和Flex 4 SDK构建Flickr浏览器
  10. android之 Activity跳转出现闪屏