progress.ts
964 Bytes
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
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import router from '@/router/index'
NProgress.configure({ showSpinner: false })
router.beforeEach((to: any, from: any, next: any) => {
// if (to.matched.length == 0) { router.push(to.path); }
NProgress.start()
const hasToken = true
const whiteList = ['/login']
// TIP 页面标题设置
globalThis.document.title = to.meta.title? to.meta.title: import.meta.env.VITE_APP_TITLE
if (hasToken) {
console.log('has')
if (to.path === '/login') {
// next({ path: '/about' })
next()
NProgress.done()
} else {
next()
NProgress.done()
}
} else {
console.log('hasnot')
if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
if (from.path !== '/') {
console.log('请重新登录')
}
next({ path: '/login' })
NProgress.done()
}
}
})
router.afterEach(() => {
NProgress.done()
})