金融产品设计及数字化营销沙盘
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

1 year ago
import NProgress from 'nprogress'; // progress bar
import 'nprogress/nprogress.css'; // progress bar style
import { RouteLocationNormalized } from 'vue-router';
import getPageTitle from '@/utils/getPageTitle';
import { getAccessToken } from '@/utils/auth'; // get token from cookie
import router from './router';
NProgress.configure({ showSpinner: false }); // NProgress Configuration
const LOGIN_PATH = '/login';
router.beforeEach(async (to: RouteLocationNormalized) => {
return true;
const isLogin = getAccessToken() !== undefined;
// 不需要权限
if (!to.meta?.requiresPermission) {
// 已登录状态访问登录页面,跳转到首页
if (to.path === LOGIN_PATH && isLogin) return '/';
NProgress.start();
return true;
}
// 没有权限
if (!hasPermission(to.meta?.requiresPermission)) {
NProgress.done();
return '/403';
}
return true;
});
router.afterEach((to: RouteLocationNormalized) => {
// set page title
document.title = getPageTitle(to.meta.title);
// finish progress bar
NProgress.done();
});
1 year ago
router.onError((error, to) => {
if (error.message.includes('Failed to fetch dynamically imported module')) {
window.location = to.fullPath;
}
});