@spacego/fe-components 0.0.2 → 0.0.3
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/lib/router/index.js +33 -24
- package/package.json +1 -1
package/lib/router/index.js
CHANGED
|
@@ -1,43 +1,52 @@
|
|
|
1
|
-
import { createBrowserRouter as
|
|
2
|
-
import { createPermissionHelpers as
|
|
3
|
-
import { createDefaultRoutes as
|
|
1
|
+
import { createBrowserRouter as a } from "react-router-dom";
|
|
2
|
+
import { createPermissionHelpers as c } from "./permission.js";
|
|
3
|
+
import { createDefaultRoutes as u } from "./routes.js";
|
|
4
4
|
import "react";
|
|
5
|
-
function
|
|
6
|
-
const { modules: n, token:
|
|
5
|
+
function R(s) {
|
|
6
|
+
const { modules: n, token: e, BaseLayout: t, routes: o = [] } = s, r = c(e), i = u(n, r, t);
|
|
7
7
|
return {
|
|
8
8
|
/** 最终合并后的路由配置 */
|
|
9
|
-
routes:
|
|
9
|
+
routes: m(i, o),
|
|
10
10
|
/** 权限帮助函数,包含 ProtectedLoader 等,用于外部调用 processRoutes */
|
|
11
11
|
permissionHelpers: r
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
const
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
function m(s, n) {
|
|
15
|
+
const e = /* @__PURE__ */ new Map();
|
|
16
|
+
return s.forEach((t) => {
|
|
17
|
+
if (t.id)
|
|
18
|
+
e.set(t.id, t);
|
|
19
|
+
else {
|
|
20
|
+
const o = t.path || `route-${Math.random().toString(36).substring(2, 9)}`;
|
|
21
|
+
e.set(o, t);
|
|
22
|
+
}
|
|
23
|
+
}), n.forEach((t) => {
|
|
24
|
+
if (t.id)
|
|
25
|
+
if (t.id === "root" && e.has("root")) {
|
|
26
|
+
const o = e.get("root"), r = t, i = [
|
|
27
|
+
...o.children || [],
|
|
23
28
|
...r.children || []
|
|
24
29
|
];
|
|
25
|
-
|
|
26
|
-
...
|
|
30
|
+
e.set("root", {
|
|
31
|
+
...o,
|
|
27
32
|
...r,
|
|
28
33
|
// 属性以 customRoot 为准
|
|
29
34
|
children: i
|
|
30
35
|
});
|
|
31
36
|
} else
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
e.set(t.id, t);
|
|
38
|
+
else {
|
|
39
|
+
const o = `custom-${t.path || Math.random().toString(36).substring(2, 9)}`;
|
|
40
|
+
e.set(o, t);
|
|
41
|
+
}
|
|
42
|
+
}), Array.from(e.values());
|
|
34
43
|
}
|
|
35
|
-
function g(
|
|
36
|
-
return
|
|
44
|
+
function g(s) {
|
|
45
|
+
return a(s);
|
|
37
46
|
}
|
|
38
47
|
export {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
u as createDefaultRoutes,
|
|
49
|
+
c as createPermissionHelpers,
|
|
50
|
+
R as createRouter,
|
|
42
51
|
g as generateRouter
|
|
43
52
|
};
|