1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-14 01:34:47 +08:00

40 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import router from '@/routers/router';
import NProgress from '@/config/nprogress';
import { GlobalStore } from '@/store';
import { AxiosCanceler } from '@/api/helper/axios-cancel';
const axiosCanceler = new AxiosCanceler();
/**
* @description 路由拦截 beforeEach路由配置无数种方法个人觉得最简便
* */
router.beforeEach((to, from, next) => {
NProgress.start();
axiosCanceler.removeAllPending();
const globalStore = GlobalStore();
if (to.name === 'entrance' && globalStore.isLogin) {
if (to.params.code === globalStore.entrance) {
globalStore.setLogStatus(false);
next({
name: 'entrance',
params: { code: globalStore.entrance },
});
NProgress.done();
return;
}
next({ name: '404' });
NProgress.done();
return;
}
if (!to.matched.some((record) => record.meta.requiresAuth)) return next();
return next();
});
router.afterEach(() => {
NProgress.done();
});
export default router;