feat: 支持路由参数

This commit is contained in:
dayjoy
2024-10-20 14:32:44 +08:00
parent 82478e51b3
commit e47cf31c07
10 changed files with 123 additions and 12 deletions

View File

@@ -10,6 +10,7 @@ function buildNestedStructure(filePaths) {
const parts = filePath.split('/').slice(2, -1); // 去掉 'src/pages' 'meta.json'
let current = root;
let parentFullRoute = '';
parts.forEach((part, index) => {
const find = current.find((item) => item._path === part);
@@ -25,9 +26,15 @@ function buildNestedStructure(filePaths) {
if (index === parts.length - 1) {
const content = fs.readFileSync(filePath, 'utf-8');
Object.assign(current, JSON.parse(content), {
const contentJSON = JSON.parse(content);
Object.assign(current, contentJSON, {
_fullpath: parts.join('/'),
_fullroute: parentFullRoute
? `${parentFullRoute}/${contentJSON.route || part}`
: contentJSON.route || part,
});
} else {
parentFullRoute = current._fullroute || parentFullRoute;
}
current = current._children;
});