把indexOf方法替换掉
router.beforeEach((to, from, next) => {
const pathArr=['/standard','/user'] //设置需要权限的路径,
if (pathArr.includes(to.Path)||to.fullPath.includes(pathArr[0]||to.fullPath.includes(pathArr[1]){ //如果to.path在上面路径内,to.path是绝对路径,to.fullPath是带参数的
const token = sessionStorage.getItem('user')//获取session
if(token){//如果有session
next()//放行
}else{
next('/login')//如果没有session跳转登录页面
}
}else{//如果to.path没有在在上面路径内,放行
next()
}
}