befly-vite 1.2.11 → 1.2.12

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.
Files changed (2) hide show
  1. package/index.browser.js +22 -4
  2. package/package.json +2 -2
package/index.browser.js CHANGED
@@ -81,21 +81,28 @@ function buildLayoutConfigs(routes, inheritLayout = "") {
81
81
  * 将 auto-routes 的 routes 按 `_数字` 规则套用布局组件,并输出 Vue Router 的 RouteRecordRaw[]。
82
82
  *
83
83
  * @param {any[]} routes
84
+ * @param {string=} rootRedirectPath
84
85
  * @param {(layoutName: string) => any} resolveLayoutComponent
85
86
  * @returns {import('vue-router').RouteRecordRaw[]}
86
87
  */
87
- export function Layouts(routes, resolveLayoutComponent) {
88
+ export function Layouts(routes, rootRedirectPath, resolveLayoutComponent) {
88
89
  if (!Array.isArray(routes)) {
89
- throw new Error("Layouts(routes, resolveLayoutComponent) 中 routes 必须是数组。");
90
+ throw new Error("Layouts(routes, rootRedirectPath, resolveLayoutComponent) 中 routes 必须是数组。");
91
+ }
92
+
93
+ if (rootRedirectPath && typeof rootRedirectPath !== "string") {
94
+ throw new Error("Layouts(routes, rootRedirectPath, resolveLayoutComponent) 中 rootRedirectPath 必须是字符串或假值。");
90
95
  }
91
96
 
92
97
  if (typeof resolveLayoutComponent !== "function") {
93
- throw new Error("Layouts(routes, resolveLayoutComponent) 中 resolveLayoutComponent 必须是函数。");
98
+ throw new Error("Layouts(routes, rootRedirectPath, resolveLayoutComponent) 中 resolveLayoutComponent 必须是函数。");
94
99
  }
95
100
 
101
+ const trimmedRootRedirectPath = typeof rootRedirectPath === "string" ? rootRedirectPath.trim() : "";
102
+
96
103
  const configs = buildLayoutConfigs(routes);
97
104
 
98
- return configs.map((config) => {
105
+ const layoutRoutes = configs.map((config) => {
99
106
  const layoutComponent = resolveLayoutComponent(config.layoutName);
100
107
 
101
108
  return {
@@ -110,4 +117,15 @@ export function Layouts(routes, resolveLayoutComponent) {
110
117
  ]
111
118
  };
112
119
  });
120
+
121
+ if (trimmedRootRedirectPath) {
122
+ return [
123
+ {
124
+ path: "/",
125
+ redirect: trimmedRootRedirectPath
126
+ }
127
+ ].concat(layoutRoutes);
128
+ }
129
+
130
+ return layoutRoutes;
113
131
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "befly-vite",
3
- "version": "1.2.11",
4
- "gitHead": "f5d17c019a58e82cfacec5ce3a1f04e3225ba838",
3
+ "version": "1.2.12",
4
+ "gitHead": "f6a260445b4fb58a43a7537c62f1f3b2463f0ff5",
5
5
  "private": false,
6
6
  "description": "Befly Vite 配置预设和插件集合",
7
7
  "keywords": [