fix: preset-build-in的route api 兼容

This commit is contained in:
wanchun 2022-06-06 18:02:24 +08:00
parent 7c689db1aa
commit 00effaaa53
2 changed files with 24 additions and 4 deletions

View File

@ -328,7 +328,7 @@ export default function (api) {
api.addCoreExports(() => [
{
specifiers: ['getRoutes', 'defineRouteMeta'],
specifiers: ['getRoutes', 'getRouter', 'getHistory', 'destroyRouter', 'defineRouteMeta'],
source: absCoreFilePath
}
]);

View File

@ -7,7 +7,8 @@ export function getRoutes() {
}
const ROUTER_BASE = '{{{ routerBase }}}';
let router = null;
let history = null;
export const createRouter = (routes) => {
const createHistory = plugin.applyPlugins({
key: 'modifyCreateHistory',
@ -17,14 +18,14 @@ export const createRouter = (routes) => {
},
initialValue: {{{ CREATE_HISTORY }}},
});
const history = createHistory(ROUTER_BASE);
history = createHistory(ROUTER_BASE);
// 修改routes
plugin.applyPlugins({
key: 'patchRoutes',
type: ApplyPluginsType.event,
args: { routes },
});
const router = createVueRouter({
router = createVueRouter({
history,
routes
});
@ -38,6 +39,25 @@ export const createRouter = (routes) => {
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 defineRouteMeta = (param)=>{
return param
}