| 123456789101112131415161718192021222324252627282930 |
- import router from '../router/index.js'
- // const routeList = router.options.routes[0].children
- const whiteList = ['/','/invite']
- router.beforeEach((to, from, next) => {
- let userToken = window.localStorage.getItem('token')
- console.log('--------------------------------aaaaaaaaaaaaaaaaaa',userToken)
- if (userToken) {
- // 已登录用户禁止访问登录页,直接跳转到目标页
- if (to.path === '/') {
- next({ path: '/cc_list' });
- } else {
- next(); // 允许访问其他受保护路径
- }
- } else {
- // 如果用户未登录,则判断是否在白名单中,如果在白名单中,则直接进入,否则重定向到登录页
- if (whiteList.includes(to.path)) {
- next()
- } else {
- console.log(to.path)
- if(to.path === '/login') {
- next()
- }else {
- next('/login')
- }
- }
- }
- })
|