@oiij/auto-router 0.0.4 → 0.0.5

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.
@@ -28,29 +28,9 @@ declare module 'vue-router' {
28
28
  * ```
29
29
  */
30
30
  declare function setupAutoRouter(router: Router, routesRaw: readonly RouteRecordRaw[]): {
31
- /**
32
- * 路由加载状态
33
- *
34
- * @type {import('vue').ComputedRef<boolean>}
35
- */
36
31
  loading: vue1.ComputedRef<boolean>;
37
- /**
38
- * 原始路由配置
39
- *
40
- * @type {readonly RouteRecordRaw[]}
41
- */
42
32
  routesRaw: readonly RouteRecordRaw[];
43
- /**
44
- * 解析并排序后的路由配置
45
- *
46
- * @type {RouteRecordRaw[]}
47
- */
48
33
  routes: RouteRecordRaw[];
49
- /**
50
- * 扁平化的路由配置
51
- *
52
- * @type {RouteRecordRaw[]}
53
- */
54
34
  flattenRoutes: RouteRecordRaw[];
55
35
  };
56
36
  /**
@@ -2,23 +2,6 @@ import { computed, ref } from "vue";
2
2
  import { cloneDeep } from "es-toolkit";
3
3
 
4
4
  //#region src/setup-auto-router.ts
5
- /**
6
- * 深度排序路由配置
7
- *
8
- * 递归地对路由配置进行排序,包括所有嵌套的子路由
9
- *
10
- * @param routes - 原始路由配置数组
11
- * @returns 排序后的路由配置数组
12
- *
13
- * @example
14
- * ```ts
15
- * const sortedRoutes = deepSortRoutes([
16
- * { path: '/about', meta: { sort: 2 } },
17
- * { path: '/home', meta: { sort: 1 } }
18
- * ])
19
- * // 结果: [{ path: '/home', ... }, { path: '/about', ... }]
20
- * ```
21
- */
22
5
  function deepSortRoutes(routes) {
23
6
  return routes.toSorted((a, b) => (a.meta?.sort ?? Infinity) - (b.meta?.sort ?? Infinity)).map((route) => {
24
7
  return {
@@ -27,25 +10,6 @@ function deepSortRoutes(routes) {
27
10
  };
28
11
  });
29
12
  }
30
- /**
31
- * 扁平化路由配置
32
- *
33
- * 将嵌套的路由结构展平为一维数组,包含所有层级的路由
34
- *
35
- * @param routes - 路由配置数组
36
- * @returns 扁平化后的路由数组
37
- *
38
- * @example
39
- * ```ts
40
- * const flattened = flattenDeepRoutes([
41
- * {
42
- * path: '/user',
43
- * children: [{ path: '/user/profile' }]
44
- * }
45
- * ])
46
- * // 结果: [{ path: '/user', ... }, { path: '/user/profile', ... }]
47
- * ```
48
- */
49
13
  function flattenDeepRoutes(routes) {
50
14
  return routes.flatMap((route) => {
51
15
  const flattened = [route];
@@ -74,12 +38,6 @@ function flattenDeepRoutes(routes) {
74
38
  * ```
75
39
  */
76
40
  function setupAutoRouter(router, routesRaw) {
77
- /**
78
- * 路由加载状态
79
- *
80
- * @remarks
81
- * 通过导航守卫自动管理,在路由切换时设置为 true,切换完成后设置为 false
82
- */
83
41
  const loading = ref(false);
84
42
  router.beforeEach(() => {
85
43
  loading.value = true;
@@ -87,19 +45,7 @@ function setupAutoRouter(router, routesRaw) {
87
45
  router.afterEach(() => {
88
46
  loading.value = false;
89
47
  });
90
- /**
91
- * 解析并排序后的路由配置
92
- *
93
- * @remarks
94
- * 使用 deepSortRoutes 对路由进行深度排序,确保所有层级的路由都按 sort 元数据排序
95
- */
96
48
  const routes = deepSortRoutes(cloneDeep(routesRaw));
97
- /**
98
- * 扁平化的路由配置
99
- *
100
- * @remarks
101
- * 使用 flattenDeepRoutes 将嵌套的路由结构展平为一维数组,方便后续处理
102
- */
103
49
  const flattenRoutes = flattenDeepRoutes(routes);
104
50
  return {
105
51
  loading: computed(() => loading.value),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oiij/auto-router",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "description": "Vue Router utilities and composables for Vue 3",
6
6
  "author": "oiij",
7
7
  "license": "MIT",