import router from './router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

NProgress.configure({ showSpinner: false })

const whiteList = ['/login', '/register', '/portal']

const isWhiteList = (path) => {
  return whiteList.some(pattern => path.startsWith(pattern))
}

router.beforeEach((to, from, next) => {
  NProgress.start()
  if (to.meta.title) {
    document.title = to.meta.title || '若依门户系统'
  }
  
  if (isWhiteList(to.path)) {
    next()
  } else {
    next()
  }
})

router.afterEach(() => {
  NProgress.done()
})
