@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 +13 -6
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +14 -7
- 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 || [];
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
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 || [];
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|