odc.xiaohui
2023-05-22 0782140a00e554ec7a1c724ecc1eb36726d994f8
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import Vue from 'vue'
import VueRouter from 'vue-router'
 
Vue.use(VueRouter)
 
const routes = [
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('../views/Login.vue')
    },
    {
        path: '/home',
        name: 'home',
        redirect: '/workbench',
        component: () => import('../views/Home.vue'),
        children: [
            {
                path: '/workbench',
                name: 'workbench',
                component: () => import('../views/workbench/Workbench.vue')
            },
            // {
            //     path: '/people',
            //     name: 'people',
            //     component: () => import('../views/manager/People.vue')
            // },
            {
                path: '/user',
                name: 'user',
                component: () => import('../views/manager/User.vue')
            },
            {
                path: '/police',
                name: 'police',
                component: () => import('../views/manager/Police.vue')
            },
            {
                path: '/entry',
                name: 'entry',
                component: () => import('../views/cause/Entry.vue')
            },
            {
                path: '/group',
                name: 'group',
                component: () => import('../views/cause/Group.vue')
            },
            // {
            //     path: '/search',
            //     name: 'search',
            //     component: () => import('../views/cause/Search.vue')
            // },
            {
                path: '/audit',
                name: 'audit',
                component: () => import('../views/common/Audit.vue')
            },
            {
                path: '/publicity',
                name: 'publicity',
                component: () => import('../views/common/Publicity.vue')
            },
            {
                path: '/announcement',
                name: 'announcement',
                component: () => import('../views/common/announcement.vue')
            },
            {
                path: '/question',
                name: 'question',
                component: () => import('../views/common/Question.vue')
            },
            {
                path: '/sensitive',
                name: 'sensitive',
                component: () => import('../views/common/Sensitive.vue')
            },
        ]
    }
]
 
const router = new VueRouter({
    routes
})
 
// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
    // to 将要访问的路径
    // from 代表从哪个路径跳转
    // next 是一个函数,表示放行
    // next() 放行   next('/login') 强制跳转
    if (to.path === '/login') return next()
    const tokenStr = window.sessionStorage.getItem('token')
    if (!tokenStr) return next('/login')
    next()
})
 
export default router