router编译时支持params
This commit is contained in:
parent
ceafb7f68a
commit
ce4349bc4f
|
|
@ -100,8 +100,9 @@ function makeWebAllRouters(namespaceDir, projectDir, routerFileDir) {
|
|||
const nsIndexJsonFile = (0, path_1.join)(namespaceDir, ns, 'index.json');
|
||||
let path2 = `/${ns}`;
|
||||
let notFound2 = '', first2 = '';
|
||||
let params2 = {};
|
||||
if ((0, fs_extra_1.existsSync)(nsIndexJsonFile)) {
|
||||
const { path, notFound, first } = require(nsIndexJsonFile);
|
||||
const { path, notFound, first, params } = require(nsIndexJsonFile);
|
||||
if (path) {
|
||||
path2 = path.replace(/\\/g, '/');
|
||||
}
|
||||
|
|
@ -114,11 +115,19 @@ function makeWebAllRouters(namespaceDir, projectDir, routerFileDir) {
|
|||
first2 = first2.slice(1);
|
||||
}
|
||||
}
|
||||
if (params) {
|
||||
params2 = params;
|
||||
}
|
||||
}
|
||||
let firstPage;
|
||||
const children = Object.values(pages).filter((ele) => ele.hasWeb).map(({ path, oakDisablePulldownRefresh }) => {
|
||||
let path2 = path;
|
||||
if (params2[path]) {
|
||||
// 如果有参数,接在path后面
|
||||
path2 += `/:${params2[path]}`;
|
||||
}
|
||||
const properties = [
|
||||
factory.createPropertyAssignment('path', factory.createStringLiteral(path)),
|
||||
factory.createPropertyAssignment('path', factory.createStringLiteral(path2)),
|
||||
factory.createPropertyAssignment('namespace', factory.createStringLiteral(ns)),
|
||||
factory.createPropertyAssignment('meta', factory.createObjectLiteralExpression([
|
||||
factory.createPropertyAssignment('oakDisablePulldownRefresh', oakDisablePulldownRefresh ? factory.createTrue() : factory.createFalse())
|
||||
|
|
|
|||
|
|
@ -161,8 +161,9 @@ function makeWebAllRouters(namespaceDir: string, projectDir: string, routerFileD
|
|||
const nsIndexJsonFile = join(namespaceDir, ns, 'index.json');
|
||||
let path2 = `/${ns}`;
|
||||
let notFound2 = '', first2 = '';
|
||||
let params2: Record<string, string> = {};
|
||||
if (existsSync(nsIndexJsonFile)) {
|
||||
const { path, notFound, first } = require(nsIndexJsonFile);
|
||||
const { path, notFound, first, params } = require(nsIndexJsonFile);
|
||||
if (path) {
|
||||
path2 = path.replace(/\\/g, '/');
|
||||
}
|
||||
|
|
@ -175,16 +176,24 @@ function makeWebAllRouters(namespaceDir: string, projectDir: string, routerFileD
|
|||
first2 = first2.slice(1);
|
||||
}
|
||||
}
|
||||
if (params) {
|
||||
params2 = params;
|
||||
}
|
||||
}
|
||||
let firstPage;
|
||||
const children = Object.values(pages).filter(
|
||||
(ele) => ele.hasWeb
|
||||
).map(
|
||||
({ path, oakDisablePulldownRefresh }) => {
|
||||
let path2 = path;
|
||||
if (params2[path]) {
|
||||
// 如果有参数,接在path后面
|
||||
path2 += `/:${params2[path]}`;
|
||||
}
|
||||
const properties = [
|
||||
factory.createPropertyAssignment(
|
||||
'path',
|
||||
factory.createStringLiteral(path)
|
||||
factory.createStringLiteral(path2)
|
||||
),
|
||||
factory.createPropertyAssignment(
|
||||
'namespace',
|
||||
|
|
|
|||
Loading…
Reference in New Issue