vitarx-router 4.0.0-beta.6 → 4.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -55,6 +55,13 @@ function validatePagesDirItem(item, index) {
|
|
|
55
55
|
if (config.exclude !== undefined && !Array.isArray(config.exclude)) {
|
|
56
56
|
throw new Error(`options.pages[${index}].exclude 必须是数组`);
|
|
57
57
|
}
|
|
58
|
+
if (config.group === true &&
|
|
59
|
+
config.prefix !== undefined &&
|
|
60
|
+
typeof config.prefix === 'string' &&
|
|
61
|
+
config.prefix !== '/' &&
|
|
62
|
+
config.prefix.endsWith('/')) {
|
|
63
|
+
throw new Error(`options.pages[${index}].prefix 当 group 为 true 时不能以 '/' 结尾,请使用 '${config.prefix.slice(0, -1)}'`);
|
|
64
|
+
}
|
|
58
65
|
return;
|
|
59
66
|
}
|
|
60
67
|
throw new Error(`options.pages[${index}] 必须是字符串或对象`);
|
|
@@ -9,10 +9,10 @@ import { ResolvedConfig } from './config/index.js';
|
|
|
9
9
|
import { type GenerateResult } from './generator/index.js';
|
|
10
10
|
import { type FilterOptions } from './parser/index.js';
|
|
11
11
|
import type { FileRouterOptions, ParsedNode } from './types/index.js';
|
|
12
|
+
export { resolvePageConfigs } from './config/resolve.js';
|
|
13
|
+
export type { GenerateResult } from './generator/index.js';
|
|
12
14
|
export type * from './types/index.js';
|
|
13
15
|
export * from './utils/logger.js';
|
|
14
|
-
export type { GenerateResult } from './generator/index.js';
|
|
15
|
-
export { resolvePageConfigs } from './config/resolve.js';
|
|
16
16
|
/**
|
|
17
17
|
* 文件路由管理器
|
|
18
18
|
*/
|
|
@@ -18,8 +18,8 @@ import { isEqualPageOptions, mergePageOptions, parseDefinePage, removeDefinePage
|
|
|
18
18
|
import { checkDefaultExport, isPageFile, isPageFileInDirs } from './parser/index.js';
|
|
19
19
|
import { parseRoutePath } from './parser/parsePage.js';
|
|
20
20
|
import { applyPathStrategy, info, normalizePathSeparator, readFileContent, resolvePathVariable, validateOptions, warn } from './utils/index.js';
|
|
21
|
-
export * from './utils/logger.js';
|
|
22
21
|
export { resolvePageConfigs } from './config/resolve.js';
|
|
22
|
+
export * from './utils/logger.js';
|
|
23
23
|
/**
|
|
24
24
|
* 文件路由管理器
|
|
25
25
|
*/
|
|
@@ -108,7 +108,7 @@ export class FileRouter {
|
|
|
108
108
|
filePath: page.dir,
|
|
109
109
|
path: this.applyPathStrategy(page.prefix)
|
|
110
110
|
};
|
|
111
|
-
route.children = this.scanPageDir(page, route);
|
|
111
|
+
route.children = this.scanPageDir({ ...page, prefix: '' }, route);
|
|
112
112
|
// 如果有子路由则添加到页面列表中
|
|
113
113
|
if (route.children.size > 0) {
|
|
114
114
|
pages.push(route);
|
|
@@ -162,7 +162,7 @@ export class FileRouter {
|
|
|
162
162
|
* @private
|
|
163
163
|
*/
|
|
164
164
|
processDir(filePath, fileName, page, parent) {
|
|
165
|
-
const pathPrefix = page.prefix;
|
|
165
|
+
const pathPrefix = parent ? '' : page.prefix;
|
|
166
166
|
const route = {
|
|
167
167
|
parent,
|
|
168
168
|
filePath,
|
|
@@ -234,7 +234,7 @@ export class FileRouter {
|
|
|
234
234
|
if (!pageOptions?.redirect && !checkDefaultExport(content, filePath))
|
|
235
235
|
return null;
|
|
236
236
|
// 最终 path
|
|
237
|
-
const finalPath = this.applyPathStrategy(page.prefix + (routePath === 'index' ? '' : routePath));
|
|
237
|
+
const finalPath = this.applyPathStrategy((parent ? '' : page.prefix) + (routePath === 'index' ? '' : routePath));
|
|
238
238
|
// 创建路由对象
|
|
239
239
|
const route = {
|
|
240
240
|
parent,
|
|
@@ -50,9 +50,10 @@ function createExportDeclarationVisitor(result, variableDeclarations) {
|
|
|
50
50
|
switch (declaration.type) {
|
|
51
51
|
case 'FunctionDeclaration':
|
|
52
52
|
case 'FunctionExpression':
|
|
53
|
+
case 'ArrowFunctionExpression':
|
|
53
54
|
result.isFunction = true;
|
|
54
55
|
break;
|
|
55
|
-
case '
|
|
56
|
+
case 'CallExpression':
|
|
56
57
|
result.isFunction = true;
|
|
57
58
|
break;
|
|
58
59
|
case 'Identifier':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitarx-router",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.7",
|
|
4
4
|
"description": "Official routing solution for Vitarx framework with declarative routing, navigation guards, dynamic routes, file-based routing with HMR, and full TypeScript support.",
|
|
5
5
|
"author": "ZhuChonglin <8210856@qq.com>",
|
|
6
6
|
"license": "MIT",
|