@wot-ui/router 1.1.0 → 1.1.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.cjs CHANGED
@@ -58,8 +58,8 @@ function normalizeUrl(url) {
58
58
 
59
59
  //#endregion
60
60
  //#region src/router.ts
61
- const routerKey = Symbol("router");
62
- const routeKey = Symbol("route");
61
+ const routerKey = Symbol("__ROUTER__");
62
+ const routeKey = Symbol("__ROUTE__");
63
63
  function createRouter(options) {
64
64
  const currentRoute = (0, vue.shallowRef)(START_LOCATION_NORMALIZED);
65
65
  const routes = options.routes || [];
@@ -157,8 +157,6 @@ function createRouter(options) {
157
157
  const finalType = typeof to === "object" && to.navType || type || "push";
158
158
  try {
159
159
  await performUniNavigate(finalType, url);
160
- currentRoute.value = targetLocation;
161
- afterGuards.forEach((guard) => guard(targetLocation, fromLocation));
162
160
  return Promise.resolve();
163
161
  } catch (error) {
164
162
  return Promise.reject(error);
@@ -327,10 +325,19 @@ function createRouter(options) {
327
325
  //#endregion
328
326
  //#region src/index.ts
329
327
  function useRouter() {
330
- return (0, vue.inject)(routerKey);
328
+ const router = (0, vue.inject)(routerKey);
329
+ if (router) return router;
330
+ else throw new Error("useRouter 只可以在 Vue 上下文中使用,请确保你已经正确地注册了 \"uni-mini-router\" 并且当前正处于 Vue 上下文中");
331
331
  }
332
332
  function useRoute() {
333
- return (0, vue.inject)(routeKey);
333
+ const currentRoute = (0, vue.inject)(routeKey);
334
+ if (currentRoute) {
335
+ const route = (0, vue.reactive)(currentRoute.value);
336
+ (0, vue.watch)(currentRoute, (to) => {
337
+ Object.assign(route, to);
338
+ });
339
+ return route;
340
+ } else throw new Error("useRoute 只可以在 Vue 上下文中使用,请确保你已经正确地注册了 \"uni-mini-router\" 并且当前正处于 Vue 上下文中");
334
341
  }
335
342
 
336
343
  //#endregion
package/dist/index.d.cts CHANGED
@@ -252,7 +252,7 @@ interface GlobalStyle {
252
252
  }
253
253
  interface RouteLocationNormalized {
254
254
  path: string;
255
- name?: string | symbol;
255
+ name?: string;
256
256
  params: RouteParams;
257
257
  query: LocationQuery;
258
258
  hash: string;
package/dist/index.d.mts CHANGED
@@ -252,7 +252,7 @@ interface GlobalStyle {
252
252
  }
253
253
  interface RouteLocationNormalized {
254
254
  path: string;
255
- name?: string | symbol;
255
+ name?: string;
256
256
  params: RouteParams;
257
257
  query: LocationQuery;
258
258
  hash: string;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { inject, shallowRef, unref } from "vue";
1
+ import { inject, reactive, shallowRef, unref, watch } from "vue";
2
2
 
3
3
  //#region src/types.ts
4
4
  const START_LOCATION_NORMALIZED = {
@@ -58,8 +58,8 @@ function normalizeUrl(url) {
58
58
 
59
59
  //#endregion
60
60
  //#region src/router.ts
61
- const routerKey = Symbol("router");
62
- const routeKey = Symbol("route");
61
+ const routerKey = Symbol("__ROUTER__");
62
+ const routeKey = Symbol("__ROUTE__");
63
63
  function createRouter(options) {
64
64
  const currentRoute = shallowRef(START_LOCATION_NORMALIZED);
65
65
  const routes = options.routes || [];
@@ -157,8 +157,6 @@ function createRouter(options) {
157
157
  const finalType = typeof to === "object" && to.navType || type || "push";
158
158
  try {
159
159
  await performUniNavigate(finalType, url);
160
- currentRoute.value = targetLocation;
161
- afterGuards.forEach((guard) => guard(targetLocation, fromLocation));
162
160
  return Promise.resolve();
163
161
  } catch (error) {
164
162
  return Promise.reject(error);
@@ -327,10 +325,19 @@ function createRouter(options) {
327
325
  //#endregion
328
326
  //#region src/index.ts
329
327
  function useRouter() {
330
- return inject(routerKey);
328
+ const router = inject(routerKey);
329
+ if (router) return router;
330
+ else throw new Error("useRouter 只可以在 Vue 上下文中使用,请确保你已经正确地注册了 \"uni-mini-router\" 并且当前正处于 Vue 上下文中");
331
331
  }
332
332
  function useRoute() {
333
- return inject(routeKey);
333
+ const currentRoute = inject(routeKey);
334
+ if (currentRoute) {
335
+ const route = reactive(currentRoute.value);
336
+ watch(currentRoute, (to) => {
337
+ Object.assign(route, to);
338
+ });
339
+ return route;
340
+ } else throw new Error("useRoute 只可以在 Vue 上下文中使用,请确保你已经正确地注册了 \"uni-mini-router\" 并且当前正处于 Vue 上下文中");
334
341
  }
335
342
 
336
343
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wot-ui/router",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "轻量级 uni-app vue3 路由库",
5
5
  "repository": {
6
6
  "type": "git",