befly-vite 1.5.17 → 1.5.18
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.
- package/index.browser.js +37 -53
- package/package.json +2 -2
package/index.browser.js
CHANGED
|
@@ -7,6 +7,36 @@
|
|
|
7
7
|
* @property {Record<string, any>=} meta
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
function normalizeRouteSegment(segment) {
|
|
11
|
+
if (segment.startsWith(":")) {
|
|
12
|
+
return segment;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return segment
|
|
16
|
+
.replace(/_/g, "-")
|
|
17
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
18
|
+
.toLowerCase();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function resolveRoutePath(path, parentPath = "") {
|
|
22
|
+
const rawPath = String(path || "");
|
|
23
|
+
const match = rawPath.match(/_(\d+)$/);
|
|
24
|
+
const cleanPath = match ? rawPath.slice(0, match.index) : rawPath;
|
|
25
|
+
const routePath =
|
|
26
|
+
cleanPath === "index"
|
|
27
|
+
? ""
|
|
28
|
+
: cleanPath
|
|
29
|
+
.split("/")
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.map((segment) => normalizeRouteSegment(segment))
|
|
32
|
+
.join("/");
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
layoutName: match ? match[1] : "",
|
|
36
|
+
path: `/${[parentPath, routePath].filter(Boolean).join("/")}`.replace(/\/+/g, "/")
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
10
40
|
/**
|
|
11
41
|
* 内部实现:根据文件名后缀 _数字 判断使用哪个布局,并直接输出最终路由。
|
|
12
42
|
*
|
|
@@ -14,66 +44,22 @@
|
|
|
14
44
|
*
|
|
15
45
|
* @param {RouteConfig[]} routes
|
|
16
46
|
* @param {(layoutName: string) => any} resolveLayoutComponent
|
|
47
|
+
* @param {import('vue-router').RouteRecordRaw[]} result
|
|
17
48
|
* @param {string=} parentPath
|
|
18
49
|
* @param {string=} inheritLayout
|
|
19
|
-
* @returns {import('vue-router').RouteRecordRaw[]}
|
|
20
50
|
*/
|
|
21
|
-
function
|
|
22
|
-
const rawPath = String(path || "");
|
|
23
|
-
const match = rawPath.match(/_(\d+)$/);
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
layoutName: match ? match[1] : "",
|
|
27
|
-
path: match ? rawPath.slice(0, match.index) : rawPath
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function normalizeRoutePath(path) {
|
|
32
|
-
return String(path || "")
|
|
33
|
-
.split("/")
|
|
34
|
-
.filter(Boolean)
|
|
35
|
-
.map((segment) => {
|
|
36
|
-
if (segment.startsWith(":")) {
|
|
37
|
-
return segment;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return segment
|
|
41
|
-
.replace(/_/g, "-")
|
|
42
|
-
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
43
|
-
.toLowerCase();
|
|
44
|
-
})
|
|
45
|
-
.join("/");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function joinRoutePath(parentPath, childPath) {
|
|
49
|
-
if (!parentPath) {
|
|
50
|
-
return childPath;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!childPath) {
|
|
54
|
-
return parentPath;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return `${parentPath}/${childPath}`;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function buildLayoutRoutes(routes, resolveLayoutComponent, parentPath = "", inheritLayout = "") {
|
|
61
|
-
/** @type {import('vue-router').RouteRecordRaw[]} */
|
|
62
|
-
const result = [];
|
|
63
|
-
|
|
51
|
+
function appendLayoutRoutes(routes, resolveLayoutComponent, result, parentPath = "", inheritLayout = "") {
|
|
64
52
|
for (const route of routes) {
|
|
65
|
-
const { layoutName, path } =
|
|
53
|
+
const { layoutName, path } = resolveRoutePath(route.path, parentPath);
|
|
66
54
|
const currentLayout = layoutName || inheritLayout;
|
|
67
|
-
const currentPath = path === "index" ? "" : normalizeRoutePath(path);
|
|
68
|
-
const fullPath = joinRoutePath(parentPath, currentPath);
|
|
69
55
|
|
|
70
56
|
if (route.children && route.children.length > 0) {
|
|
71
|
-
|
|
57
|
+
appendLayoutRoutes(route.children, resolveLayoutComponent, result, path, currentLayout);
|
|
72
58
|
continue;
|
|
73
59
|
}
|
|
74
60
|
|
|
75
61
|
result.push({
|
|
76
|
-
path:
|
|
62
|
+
path: path,
|
|
77
63
|
component: resolveLayoutComponent(currentLayout || "default"),
|
|
78
64
|
meta: route.meta,
|
|
79
65
|
children: [
|
|
@@ -84,8 +70,6 @@ function buildLayoutRoutes(routes, resolveLayoutComponent, parentPath = "", inhe
|
|
|
84
70
|
]
|
|
85
71
|
});
|
|
86
72
|
}
|
|
87
|
-
|
|
88
|
-
return result;
|
|
89
73
|
}
|
|
90
74
|
|
|
91
75
|
/**
|
|
@@ -110,8 +94,8 @@ export function Layouts(routes, rootRedirectPath, resolveLayoutComponent) {
|
|
|
110
94
|
}
|
|
111
95
|
|
|
112
96
|
const trimmedRootRedirectPath = typeof rootRedirectPath === "string" ? rootRedirectPath.trim() : "";
|
|
113
|
-
|
|
114
|
-
|
|
97
|
+
const layoutRoutes = [];
|
|
98
|
+
appendLayoutRoutes(routes, resolveLayoutComponent, layoutRoutes);
|
|
115
99
|
|
|
116
100
|
if (trimmedRootRedirectPath && trimmedRootRedirectPath !== "/") {
|
|
117
101
|
return [
|
package/package.json
CHANGED