progress.ts
837 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
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) => {
NProgress.start()
const hasToken = 1 && 1
const whiteList = ['/login']
// TIP 页面标题设置
globalThis.document.title = to.meta.title? to.meta.title: import.meta.env.VITE_APP_TITLE
if (hasToken) {
if (to.path === '/login') {
next({ path: '/about' })
NProgress.done()
} else {
next()
NProgress.done()
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
if (from.path !== '/') {
console.log('请重新登录')
}
next({ path: '/login' })
NProgress.done()
}
}
})
router.afterEach(() => {
NProgress.done()
})