mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
feat: 优化router.mode,支持全部配置
This commit is contained in:
parent
766d09483d
commit
54404abb47
@ -170,7 +170,8 @@ const fix = function (routes) {
|
|||||||
|
|
||||||
const getRoutes = function ({ config, absPagesPath }) {
|
const getRoutes = function ({ config, absPagesPath }) {
|
||||||
// 用户配置了routes则使用用户配置的
|
// 用户配置了routes则使用用户配置的
|
||||||
if (config.router.routes) return config.router.routes;
|
const configRoutes = config.router.routes;
|
||||||
|
if (configRoutes && configRoutes.length > 0) return configRoutes;
|
||||||
|
|
||||||
const routes = [];
|
const routes = [];
|
||||||
genRoutes(routes, absPagesPath, '/', config);
|
genRoutes(routes, absPagesPath, '/', config);
|
||||||
@ -224,7 +225,9 @@ export default function (api) {
|
|||||||
mode: joi.string()
|
mode: joi.string()
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
default: {}
|
default: {
|
||||||
|
mode: 'hash'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -260,9 +263,16 @@ export default function (api) {
|
|||||||
|
|
||||||
const absRuntimeFilePath = join(namespace, 'runtime.js');
|
const absRuntimeFilePath = join(namespace, 'runtime.js');
|
||||||
|
|
||||||
|
const historyType = {
|
||||||
|
h5: 'createWebHistory',
|
||||||
|
hash: 'createWebHashHistory',
|
||||||
|
memory: 'createMemoryHistory'
|
||||||
|
};
|
||||||
|
|
||||||
api.onGenerateFiles(async () => {
|
api.onGenerateFiles(async () => {
|
||||||
const routesTpl = readFileSync(join(__dirname, 'template/routes.tpl'), 'utf-8');
|
const routesTpl = readFileSync(join(__dirname, 'template/routes.tpl'), 'utf-8');
|
||||||
const routes = await api.getRoutesJSON();
|
const routes = await api.getRoutesJSON();
|
||||||
|
|
||||||
api.writeTmpFile({
|
api.writeTmpFile({
|
||||||
path: absCoreFilePath,
|
path: absCoreFilePath,
|
||||||
content: Mustache.render(routesTpl, {
|
content: Mustache.render(routesTpl, {
|
||||||
@ -270,7 +280,7 @@ export default function (api) {
|
|||||||
routes,
|
routes,
|
||||||
config: api.config,
|
config: api.config,
|
||||||
routerBase: api.config.base || '',
|
routerBase: api.config.base || '',
|
||||||
CREATE_HISTORY: api.config.router.mode === 'history' ? 'createWebHistory' : 'createWebHashHistory'
|
CREATE_HISTORY: historyType[api.config.router.mode] || 'createWebHashHistory'
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user