@wot-ui/router 1.1.0 → 1.1.1

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 || [];
@@ -327,10 +327,19 @@ function createRouter(options) {
327
327
  //#endregion
328
328
  //#region src/index.ts
329
329
  function useRouter() {
330
- return (0, vue.inject)(routerKey);
330
+ const router = (0, vue.inject)(routerKey);
331
+ if (router) return router;
332
+ else throw new Error("useRouter 只可以在 Vue 上下文中使用,请确保你已经正确地注册了 \"uni-mini-router\" 并且当前正处于 Vue 上下文中");
331
333
  }
332
334
  function useRoute() {
333
- return (0, vue.inject)(routeKey);
335
+ const currentRoute = (0, vue.inject)(routeKey);
336
+ if (currentRoute) {
337
+ const route = (0, vue.reactive)(currentRoute.value);
338
+ (0, vue.watch)(currentRoute, (to) => {
339
+ Object.assign(route, to);
340
+ });
341
+ return route;
342
+ } else throw new Error("useRoute 只可以在 Vue 上下文中使用,请确保你已经正确地注册了 \"uni-mini-router\" 并且当前正处于 Vue 上下文中");
334
343
  }
335
344
 
336
345
  //#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 || [];
@@ -327,10 +327,19 @@ function createRouter(options) {
327
327
  //#endregion
328
328
  //#region src/index.ts
329
329
  function useRouter() {
330
- return inject(routerKey);
330
+ const router = inject(routerKey);
331
+ if (router) return router;
332
+ else throw new Error("useRouter 只可以在 Vue 上下文中使用,请确保你已经正确地注册了 \"uni-mini-router\" 并且当前正处于 Vue 上下文中");
331
333
  }
332
334
  function useRoute() {
333
- return inject(routeKey);
335
+ const currentRoute = inject(routeKey);
336
+ if (currentRoute) {
337
+ const route = reactive(currentRoute.value);
338
+ watch(currentRoute, (to) => {
339
+ Object.assign(route, to);
340
+ });
341
+ return route;
342
+ } else throw new Error("useRoute 只可以在 Vue 上下文中使用,请确保你已经正确地注册了 \"uni-mini-router\" 并且当前正处于 Vue 上下文中");
334
343
  }
335
344
 
336
345
  //#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.1",
4
4
  "description": "轻量级 uni-app vue3 路由库",
5
5
  "repository": {
6
6
  "type": "git",