up
chenyc
2022-07-04 5d61d2535302e9d472b650e2607a8cfbbdff1d18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {
    createRouter, createWebHashHistory, RouteRecordRaw,
} from 'vue-router'
import { Session } from '@/utils/storage'
 
const routes: Array<RouteRecordRaw> = [
    // { path: '/', name: 'Home', component: () => import('@/views/home/index.vue')},
    { path: '/', name: 'test', component: () => import('@/views/home/index.vue')},
    { path: '/test', name: 'Home', component: () => import('@/views/test/index.vue')},
    { path: '/login', name: 'login', component: () => import('@/views/login/index.vue')},
]
 
const router = createRouter({
    history: createWebHashHistory(),    // history 模式则使用 createWebHistory()
    routes,
})
// 路由加载前
// router.beforeEach(async(to, from, next) => {
//     // console.log(to, 'to')
//     const token = Session.get('token')
//     if (to.path === '/login' && !token) {
//         next()
//     }
//     else {
//         if (!token||to.path === '/login') {
//             console.log('如果toke为空,就定位到登录页')
//             next('/test')
//             Session.clear()
//         } else {
//             next()
//         }
        
//     }
// })
 
export default router