@oiij/auto-router 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/dist/index.d.mts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { AutoRouterInstance } from "./setup-auto-router.mjs";
2
+ import * as vue0 from "vue";
2
3
  import { App } from "vue";
3
- import { RouteRecordRaw } from "vue-router";
4
+ import * as vue_router0 from "vue-router";
5
+ import { RouteRecordRaw, Router } from "vue-router";
4
6
 
5
7
  //#region src/index.d.ts
6
8
  /**
@@ -23,23 +25,34 @@ declare function useAutoRouter(): AutoRouterInstance;
23
25
  *
24
26
  * 必须在 Vue Router 之后安装
25
27
  *
28
+ * @param router Vue Router 实例
29
+ * @param routes 路由配置数组
26
30
  * @returns Vue 插件对象
27
31
  *
28
32
  * @example
29
33
  * ```ts
30
34
  * import { createApp } from 'vue'
31
35
  * import { createRouter } from 'vue-router'
36
+ * import { routes } from 'vue-router/auto-routes'
37
+
32
38
  * import { createAutoRouter } from '@oiij/auto-router'
33
39
  *
34
40
  * const app = createApp(App)
35
41
  * const router = createRouter({ ... })
36
42
  *
37
43
  * app.use(router)
38
- * app.use(createAutoRouter())
44
+ * app.use(createAutoRouter(router, routes))
39
45
  * app.mount('#app')
40
46
  * ```
41
47
  */
42
- declare function createAutoRouter(routes: readonly RouteRecordRaw[]): {
48
+ declare function createAutoRouter(router: Router, routes: readonly RouteRecordRaw[]): {
49
+ loading: vue0.ComputedRef<boolean>;
50
+ routesRaw: readonly RouteRecordRaw[];
51
+ routes: RouteRecordRaw[];
52
+ flattenRoutes: RouteRecordRaw[];
53
+ keepAlivePath: vue0.ComputedRef<string[]>;
54
+ currentRoute: vue0.ComputedRef<vue_router0.RouteLocationNormalizedLoaded>;
55
+ currentRoutePath: vue0.ComputedRef<string>;
43
56
  install(app: App): void;
44
57
  };
45
58
  //#endregion
package/dist/index.mjs CHANGED
@@ -27,29 +27,35 @@ function useAutoRouter() {
27
27
  *
28
28
  * 必须在 Vue Router 之后安装
29
29
  *
30
+ * @param router Vue Router 实例
31
+ * @param routes 路由配置数组
30
32
  * @returns Vue 插件对象
31
33
  *
32
34
  * @example
33
35
  * ```ts
34
36
  * import { createApp } from 'vue'
35
37
  * import { createRouter } from 'vue-router'
38
+ * import { routes } from 'vue-router/auto-routes'
39
+
36
40
  * import { createAutoRouter } from '@oiij/auto-router'
37
41
  *
38
42
  * const app = createApp(App)
39
43
  * const router = createRouter({ ... })
40
44
  *
41
45
  * app.use(router)
42
- * app.use(createAutoRouter())
46
+ * app.use(createAutoRouter(router, routes))
43
47
  * app.mount('#app')
44
48
  * ```
45
49
  */
46
- function createAutoRouter(routes) {
47
- return { install(app) {
48
- const router = app.config.globalProperties.$router;
49
- if (!router) throw new Error("Router instance is not found on this Vue app. This plugin should be installed after Vue Router.");
50
- const autoRouter = setupAutoRouter(router, routes);
51
- app.provide(__INJECTION_KEY__, autoRouter);
52
- } };
50
+ function createAutoRouter(router, routes) {
51
+ const autoRouter = setupAutoRouter(router, routes);
52
+ return {
53
+ install(app) {
54
+ app.config.globalProperties.$autoRouter = autoRouter;
55
+ app.provide(__INJECTION_KEY__, autoRouter);
56
+ },
57
+ ...autoRouter
58
+ };
53
59
  }
54
60
 
55
61
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { ComputedRef } from "vue";
2
- import { RouteLocationNormalizedLoaded, RouteRecordRaw } from "vue-router";
2
+ import { RouteLocationNormalizedLoaded, RouteRecordRaw, Router } from "vue-router";
3
3
 
4
4
  //#region src/setup-auto-router.d.ts
5
5
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oiij/auto-router",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "description": "Vue Router utilities and composables for Vue 3",
6
6
  "author": "oiij",
7
7
  "license": "MIT",