@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 +13 -4
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +14 -5
- package/package.json +1 -1
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("
|
|
62
|
-
const routeKey = Symbol("
|
|
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
|
-
|
|
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
|
-
|
|
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
package/dist/index.d.mts
CHANGED
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("
|
|
62
|
-
const routeKey = Symbol("
|
|
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
|
-
|
|
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
|
-
|
|
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
|