当前位置:网站首页>router.beforEach
router.beforEach
2022-08-11 11:51:00 【-加油】
未完伪代码
import Vue from 'vue'
import Router from 'vue-router'
import xxx from 'xxx.vue'
Vue.use(Router)
const routes = [
{
path:'/xxx',
name:'xxx',
component:xxx
},
]
const router = new Router({
mode: 'history',
routes
})
router.beforEach((to,from,next)=>{
//获取token的方法可以进行封装
const token = window.sessionStorage.getItem('token')
//没有登录 且 不是访问登录页
if(!token&&to.path!=='/login'){
//游客可访问的页面
if(hasAccessBeLogined(to.path)){
next()
}else{
next('/login')
}
}
//没有登录 去登录
else if(!token&&to.path==='/login'){
next()
}
//登陆了 去登录页
else if(token&&to.path==='/login'){
next()
}else{
//登录了 且没去登录页 需要进行权限鉴定
//还没实现
}
})
export default router
边栏推荐
猜你喜欢
随机推荐
2022HW 涉及的需要修复的 0day 漏洞 总结
Simple to use NLP annotation tool the Brat
路测数据合并
MySQL --- 存储引擎
六月成功案例
PlutoSDR学习指南【2】无线数据传输
Grid 布局介绍
Qt中的窗口单例不要用饿汉式
集合面试题
[10点公开课]:AV1编码器的优化及其在流媒体和实时通讯中的应用
何为API服务网关
公共经济学(开卷)期末复习题
Application practice of low-latency real-time audio and video in 5G remote control scenarios
亏了3000亿,巴菲特:这也叫亏?
条件竞争 && pipe_buffer + 堆喷射
三面蚂蚁金服,分享面试经历总结(已拿offer)
VirtualLab:Ince-Gaussian光束产生涡旋阵列激光束的观测
继承和多态的总结
重要消息丨.NET Core 3.1 将于今年12月13日结束支持
Shaanxi cas: 2055042-71-0N-(alkyne-tetraethylene glycol)-biotin price









