需求:

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

遇到的问题:

一开始是打算直接在拦截器跳转路由的,发现会报错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. iOS8+ UITableView自动计算cell高度并缓存
  2. Linq中的group by多表多字段,Sum求和
  3. node php聊天室,最简单的Nodejs聊天室示例
  4. vs code ipynb文件_UE4引擎 源码的获取、安装,以及VS配置
  5. hdu 5172 GTY's gay friends(线段树最值)
  6. SUSE Labs Con 2018有感
  7. 基于matlab的捷联惯导算法设计及仿真,基于 Matlab 的捷联惯导算法设计及仿真1.doc...
  8. 旧物手工机器人制作图片_自制送给小朋友的生日礼物,DIY帅气的不织布机器人...
  9. Hybird接口的理解
  10. 2021-CSP-J2/S2 自我题解
  11. android 代码设置 键盘适应_实现Android键盘的中英文适配
  12. PostgreSQL下载地址
  13. NYOJ234吃土豆(双层动态规划)
  14. EKS使用AWS EFS CSI
  15. 如何将eclipse项目和svn关联(从服务器取项目)
  16. 移动安全 第六天-Iot安全
  17. 关于淘淘商城的一些基本说明
  18. 电脑版微信怎么双开、多开 超级简单
  19. CreateCompatibleDC 说明
  20. 单核处理器、多核处理器、多处理器与多线程编程

热门文章

  1. html5 自动设置全屏,HTML5全屏(Fullscreen)API详细介绍
  2. is在python中是什么意思_【IT专家】关键字:is和=在python中有什么区别
  3. Smartfoxserver点滴
  4. 树莓派上使用网络抓包工具Wireshark on your Raspberry Pi 4B
  5. python牛顿迭代法求平方根_牛顿迭代法计算平方根
  6. 【对汇编语言又爱又恨?那是没找对方法或者合适的书】
  7. linux设置服务器定时重启吗,Centos7配置定时重启服务器
  8. 【PyTorch深度学习实践 | 刘二大人】B站视频教程笔记
  9. 前端上传文件status状态为0?
  10. 360显示服务器内存,为什么我的电脑每次开机360显示内存占用了70以上,而且电脑蛮卡? 爱问知识人...