| 12345678910111213141516171819202122232425262728 |
- import router from '@/router'
- import { getToken } from '@/utils/cache/cookies'
- import NProgress from 'nprogress'
- import 'nprogress/nprogress.css'
- NProgress.configure({ showSpinner: false })
- router.beforeEach(async (to, _form, next) => {
- NProgress.start()
- const token = getToken()
- if (!token) {
- if (to.path !== '/login') {
- next('/login')
- } else {
- next()
- }
- } else {
- if (to.path === '/login') {
- next({ path: '/' })
- } else {
- next()
- }
- }
- })
- router.afterEach(() => {
- NProgress.done()
- })
|