12345678910111213141516171819202122232425262728293031323334353637383940 |
- import router from './router';
- import { getSessionID, getConfig } from '@/utils/auth';
- import NProgress from 'nprogress';
- import 'nprogress/nprogress.css';
- NProgress.configure({ showSpinner: false });
- const whiteList = ['/login', '/EnterSys']; // 重定向白名单
- // 全局前置守卫
- router.beforeEach(async (to, from, next) => {
- NProgress.start();
- const { isHas } = getConfig();
- if (getSessionID() && isHas) {
- if (to.path === '/login') {
- next({ path: '/' });
- NProgress.done();
- } else {
- next();
- }
- } else if (whiteList.includes(to.path)) {
- // 在登录白名单中,直接进入
- next();
- } else {
- // 其他无权访问的页面将重定向到登录页面
- if (process.env.NODE_ENV === 'production') {
- window.location.href = '/';
- } else {
- next('/login');
- }
- NProgress.done();
- }
- });
- // 全局后置钩子
- router.afterEach(() => {
- NProgress.done();
- });
|