@oiij/auto-router 0.0.1 → 0.0.2

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,5 +1,6 @@
1
1
  import { AutoRouterInstance } from "./setup-auto-router.mjs";
2
2
  import { App } from "vue";
3
+ import { RouteRecordRaw } from "vue-router";
3
4
 
4
5
  //#region src/index.d.ts
5
6
  /**
@@ -38,7 +39,7 @@ declare function useAutoRouter(): AutoRouterInstance;
38
39
  * app.mount('#app')
39
40
  * ```
40
41
  */
41
- declare function createAutoRouter(): {
42
+ declare function createAutoRouter(routes: readonly RouteRecordRaw[]): {
42
43
  install(app: App): void;
43
44
  };
44
45
  //#endregion
package/dist/index.mjs CHANGED
@@ -43,11 +43,11 @@ function useAutoRouter() {
43
43
  * app.mount('#app')
44
44
  * ```
45
45
  */
46
- function createAutoRouter() {
46
+ function createAutoRouter(routes) {
47
47
  return { install(app) {
48
48
  const router = app.config.globalProperties.$router;
49
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);
50
+ const autoRouter = setupAutoRouter(router, routes);
51
51
  app.provide(__INJECTION_KEY__, autoRouter);
52
52
  } };
53
53
  }
@@ -1,6 +1,5 @@
1
1
  import { computed, ref } from "vue";
2
2
  import { cloneDeep } from "es-toolkit";
3
- import { routes as routes$1 } from "vue-router/auto-routes";
4
3
 
5
4
  //#region src/setup-auto-router.ts
6
5
  /**
@@ -59,7 +58,7 @@ function flattenRoutes(routes) {
59
58
  * console.log(autoRouter.flattenRoutes) // 扁平化路由
60
59
  * ```
61
60
  */
62
- function setupAutoRouter(router) {
61
+ function setupAutoRouter(router, routesRaw) {
63
62
  const loading = ref(false);
64
63
  router.beforeEach((to, from, next) => {
65
64
  loading.value = true;
@@ -68,14 +67,14 @@ function setupAutoRouter(router) {
68
67
  router.afterEach(() => {
69
68
  loading.value = false;
70
69
  });
71
- const routes = parseRoutes(cloneDeep(routes$1));
70
+ const routes = parseRoutes(cloneDeep(routesRaw));
72
71
  const flattenRoutesCache = flattenRoutes(routes);
73
72
  const keepAlivePath = computed(() => flattenRoutesCache.filter((f) => f.meta?.keepAlive).map((m) => m.path));
74
73
  const currentRoute = computed(() => router.currentRoute.value);
75
74
  const currentRoutePath = computed(() => currentRoute.value.path);
76
75
  return {
77
76
  loading: computed(() => loading.value),
78
- routesRaw: routes$1,
77
+ routesRaw,
79
78
  routes,
80
79
  flattenRoutes: flattenRoutesCache,
81
80
  keepAlivePath,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oiij/auto-router",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "description": "Vue Router utilities and composables for Vue 3",
6
6
  "author": "oiij",
7
7
  "license": "MIT",