mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-10-15 12:02:18 +08:00
67 lines
1.3 KiB
Smarty
67 lines
1.3 KiB
Smarty
import { createRouter as createVueRouter, {{{ CREATE_HISTORY }}}, ApplyPluginsType } from '{{{ runtimePath }}}';
|
|
import { plugin } from '@@/core/coreExports';
|
|
|
|
export function getRoutes() {
|
|
const routes = {{{ routes }}};
|
|
return routes;
|
|
}
|
|
|
|
const ROUTER_BASE = '{{{ routerBase }}}';
|
|
let router = null;
|
|
let history = null;
|
|
export const createRouter = (routes) => {
|
|
if (router) {
|
|
return router;
|
|
}
|
|
const createHistory = plugin.applyPlugins({
|
|
key: 'modifyCreateHistroy',
|
|
type: ApplyPluginsType.modify,
|
|
args: {
|
|
base: ROUTER_BASE
|
|
},
|
|
initialValue: {{{ CREATE_HISTORY }}},
|
|
});
|
|
history = createHistory(ROUTER_BASE);
|
|
// 修改routes
|
|
plugin.applyPlugins({
|
|
key: 'patchRoutes',
|
|
type: ApplyPluginsType.event,
|
|
args: { routes },
|
|
});
|
|
router = createVueRouter({
|
|
history,
|
|
routes
|
|
});
|
|
|
|
plugin.applyPlugins({
|
|
key: 'onRouterCreated',
|
|
type: ApplyPluginsType.event,
|
|
args: { router },
|
|
});
|
|
|
|
return router;
|
|
};
|
|
|
|
export const getRouter = ()=>{
|
|
if(!router){
|
|
console.warn(`[preset-build-in] router is null`)
|
|
}
|
|
return router;
|
|
}
|
|
|
|
export const getHistory = ()=>{
|
|
if(!history){
|
|
console.warn(`[preset-build-in] history is null`)
|
|
}
|
|
return history;
|
|
}
|
|
|
|
export const destroyRouter = ()=>{
|
|
router = null;
|
|
history = null;
|
|
}
|
|
|
|
export const defineRoute = (param)=>{
|
|
return param
|
|
}
|