mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
32 lines
913 B
Smarty
32 lines
913 B
Smarty
import { access, install } from "./core";
|
|
import { plugin, ApplyPluginsType } from "@@/core/coreExports";
|
|
|
|
export function onRouterCreated({ router }) {
|
|
router.beforeEach(async (to, from, next) => {
|
|
let path;
|
|
if (to.matched.length === 1) {
|
|
path = to.matched[0].path;
|
|
} else {
|
|
path = to.path;
|
|
}
|
|
const canRoute = await access.hasAccess(path);
|
|
if (canRoute) {
|
|
next();
|
|
} else {
|
|
const noAccessHandler = plugin.applyPlugins({
|
|
key: "noAccessHandler",
|
|
type: ApplyPluginsType.modify,
|
|
initialValue: null,
|
|
});
|
|
if (noAccessHandler && typeof noAccessHandler === "function") {
|
|
noAccessHandler(router, to, from);
|
|
}
|
|
next(false);
|
|
}
|
|
});
|
|
}
|
|
|
|
export function onAppCreated({ app }) {
|
|
install(app)
|
|
}
|