1234567891011121314151617181920212223242526272829303132333435 |
- 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']; // 重定向白名单
- // 全局前置守卫
- 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 {
- // 其他无权访问的页面将重定向到登录页面
- next(`/login`);
- NProgress.done();
- }
- });
- // 全局后置钩子
- router.afterEach(() => {
- NProgress.done();
- });
|