import router from './router' import { useNProgress } from '@/hooks/web/useNProgress' import { useTitle } from '@/hooks/web/useTitle' import { getToken, removeToken } from '@/utils/auth' const { start, done } = useNProgress() // 路由不重定向白名单 // const whiteList = [ // '/', // '/home', // '/login', // '/social-login', // '/auth-redirect', // '/bind', // '/register', // '/privacyPolicy', // '/userAgreement', // '/recruit/company', // '/recruit/position', // '/recruit/position/details', // ] // loginType:1.enterprise: 企业路由 // 2.personal: 个人路由 // 3.noLogin: 无需登录也能访问的页面(personal里面的一种特殊类型,企业都需要登录) // 路由守卫 router.beforeEach(async (to, from, next) => { start() // loadStart() if (getToken()) { if (to.path === '/login') { next({ path: '/' }) } else { const type = localStorage.getItem('loginType') // 判断企业路由和个人路由,防止互串 if (!type) { removeToken(); next(`/login?redirect=${to.fullPath}`) } else if (type === 'personal' && to.meta?.loginType === 'noLogin') next() else if (to.meta?.loginType === type) next() else next({ path: `/${type}` }) // next() } } else { if (to.meta?.loginType === 'noLogin') { // 页面不需要登录 next() } else { next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 } } }) router.afterEach((to) => { useTitle(to?.meta?.title) done() // 结束Progress // loadDone() })