progress.ts 833 Bytes
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']
  
  // 页面标题设置
  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()
})