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
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
{
path: '/',
redirect: '/commit',
},
{
path: '/screen',
name: 'screen',
meta: {
title: '大屏'
},
component: () => import('@/views/screen')
},
{
path: '/login',
name: 'login',
meta: {
title: '登录'
},
component: () => import('@/views/login')
},
{
path: '/success',
name: 'success',
meta: {
title: '操作成功'
},
component: () => import('@/views/success')
},
{
path: '/opt',
name: 'opt',
meta: {
title: '运维'
},
component: () => import('@/views/setTopBoxManage/opt')
},
{
path: '/commit',
name: 'commit',
component: () => import('@/views/user/commit.vue')
},
{
path: '/learn',
name: 'learn',
component: () => import('@/views/user/learn.vue')
},
{
path: '/admin',
name: 'admin',
component: () => import('@/views/user/admin.vue')
},
{
path: '/editPsd',
name: 'editPsd',
component: () => import('@/views/user/editPsd.vue')
},
{
path: '/learnContent',
name: 'learnContent',
component: () => import('@/views/user/components/learnContent.vue')
},
{
path: '/learnDetail',
name: 'learnDetail',
component: () => import('@/views/user/components/learnDetail.vue')
},
{
path: '/adminInfo',
name: 'adminInfo',
component: () => import('@/views/user/components/adminInfo.vue')
},
]
function getAbsolutePath () {
let path = location.pathname
return path.substring(0, path.lastIndexOf('/') + 1)
}
const router = new VueRouter({
routes: routes,
mode: "history",
base: getAbsolutePath()
})
const whiteList =['/login','/success','/screen']
router.beforeEach((to, from, next) => {
let user = localStorage.getItem("token");
if (!user && !whiteList.includes(to.path)) { // 通过vuex state获取当前的token是否存在
next({
path: '/login',
})
}else {
next();
}
})
export default router