@esmx/router 3.0.0-rc.24 → 3.0.0-rc.26
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/error.mjs +14 -11
- package/dist/increment-id.mjs +6 -1
- package/dist/location.mjs +3 -2
- package/dist/location.test.mjs +7 -7
- package/dist/matcher.mjs +1 -1
- package/dist/matcher.test.mjs +5 -5
- package/dist/micro-app.mjs +9 -4
- package/dist/navigation.d.ts +3 -1
- package/dist/navigation.mjs +28 -18
- package/dist/options.mjs +13 -12
- package/dist/route-task.mjs +6 -1
- package/dist/route-transition.mjs +17 -13
- package/dist/route-transition.test.mjs +1 -1
- package/dist/route.mjs +31 -28
- package/dist/route.test.mjs +4 -4
- package/dist/router-back.test.mjs +1 -1
- package/dist/router-forward.test.mjs +1 -1
- package/dist/router-link.mjs +12 -7
- package/dist/router-restart-app.dom.test.mjs +6 -6
- package/dist/router-window-navigation.test.mjs +32 -32
- package/dist/router.mjs +49 -31
- package/dist/types.d.ts +4 -2
- package/dist/util.test.mjs +18 -18
- package/package.json +8 -8
- package/src/navigation.ts +9 -2
- package/src/route-transition.ts +1 -1
- package/src/router-link.ts +20 -17
- package/src/router.ts +15 -3
- package/src/types.ts +7 -2
package/dist/error.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1
4
|
export class RouteError extends Error {
|
|
2
|
-
code;
|
|
3
|
-
to;
|
|
4
|
-
from;
|
|
5
5
|
constructor(message, code, to, from = null) {
|
|
6
6
|
super(message);
|
|
7
|
+
__publicField(this, "code");
|
|
8
|
+
__publicField(this, "to");
|
|
9
|
+
__publicField(this, "from");
|
|
7
10
|
this.name = "RouteError";
|
|
8
11
|
this.code = code;
|
|
9
12
|
this.to = to;
|
|
@@ -11,39 +14,39 @@ export class RouteError extends Error {
|
|
|
11
14
|
}
|
|
12
15
|
}
|
|
13
16
|
export class RouteTaskCancelledError extends RouteError {
|
|
14
|
-
taskName;
|
|
15
17
|
constructor(taskName, to, from = null) {
|
|
16
18
|
super(
|
|
17
|
-
|
|
19
|
+
'Route task "'.concat(taskName, '" was cancelled'),
|
|
18
20
|
"ROUTE_TASK_CANCELLED",
|
|
19
21
|
to,
|
|
20
22
|
from
|
|
21
23
|
);
|
|
24
|
+
__publicField(this, "taskName");
|
|
22
25
|
this.name = "RouteTaskCancelledError";
|
|
23
26
|
this.taskName = taskName;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
export class RouteTaskExecutionError extends RouteError {
|
|
27
|
-
taskName;
|
|
28
|
-
originalError;
|
|
29
30
|
constructor(taskName, to, from = null, originalError) {
|
|
30
31
|
const error = originalError instanceof Error ? originalError : new Error(String(originalError));
|
|
31
|
-
const message =
|
|
32
|
+
const message = 'Route task "'.concat(taskName, '" failed').concat(error.message ? ": ".concat(error.message) : "");
|
|
32
33
|
super(message, "ROUTE_TASK_EXECUTION_ERROR", to, from);
|
|
34
|
+
__publicField(this, "taskName");
|
|
35
|
+
__publicField(this, "originalError");
|
|
33
36
|
this.name = "RouteTaskExecutionError";
|
|
34
37
|
this.taskName = taskName;
|
|
35
38
|
this.originalError = error;
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
export class RouteNavigationAbortedError extends RouteError {
|
|
39
|
-
taskName;
|
|
40
42
|
constructor(taskName, to, from = null) {
|
|
41
43
|
super(
|
|
42
|
-
|
|
44
|
+
'Navigation was aborted by task "'.concat(taskName, '"'),
|
|
43
45
|
"ROUTE_NAVIGATION_ABORTED",
|
|
44
46
|
to,
|
|
45
47
|
from
|
|
46
48
|
);
|
|
49
|
+
__publicField(this, "taskName");
|
|
47
50
|
this.name = "RouteNavigationAbortedError";
|
|
48
51
|
this.taskName = taskName;
|
|
49
52
|
}
|
|
@@ -51,7 +54,7 @@ export class RouteNavigationAbortedError extends RouteError {
|
|
|
51
54
|
export class RouteSelfRedirectionError extends RouteError {
|
|
52
55
|
constructor(fullPath, to, from = null) {
|
|
53
56
|
super(
|
|
54
|
-
|
|
57
|
+
'Detected a self-redirection to "'.concat(fullPath, '". Aborting navigation.'),
|
|
55
58
|
"ROUTE_SELF_REDIRECTION",
|
|
56
59
|
to,
|
|
57
60
|
from
|
package/dist/increment-id.mjs
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1
4
|
export class IncrementId {
|
|
2
|
-
|
|
5
|
+
constructor() {
|
|
6
|
+
__publicField(this, "value", 0);
|
|
7
|
+
}
|
|
3
8
|
equal(id) {
|
|
4
9
|
return this.value === id;
|
|
5
10
|
}
|
package/dist/location.mjs
CHANGED
|
@@ -4,7 +4,7 @@ export function normalizeURL(url, base) {
|
|
|
4
4
|
return url;
|
|
5
5
|
}
|
|
6
6
|
if (url.startsWith("//")) {
|
|
7
|
-
return new URL(
|
|
7
|
+
return new URL("http:".concat(url));
|
|
8
8
|
}
|
|
9
9
|
if (url.startsWith("/")) {
|
|
10
10
|
const newBase = new URL(".", base);
|
|
@@ -19,10 +19,11 @@ export function normalizeURL(url, base) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
export function parseLocation(toInput, baseURL) {
|
|
22
|
+
var _a, _b;
|
|
22
23
|
if (typeof toInput === "string") {
|
|
23
24
|
return normalizeURL(toInput, baseURL);
|
|
24
25
|
}
|
|
25
|
-
const url = normalizeURL(toInput.path
|
|
26
|
+
const url = normalizeURL((_b = (_a = toInput.path) != null ? _a : toInput.url) != null ? _b : "", baseURL);
|
|
26
27
|
const searchParams = url.searchParams;
|
|
27
28
|
const mergedQuery = {};
|
|
28
29
|
if (toInput.query) {
|
package/dist/location.test.mjs
CHANGED
|
@@ -4,7 +4,7 @@ expect.extend({
|
|
|
4
4
|
toEqURL: (received, expected) => {
|
|
5
5
|
if (!(received instanceof URL)) {
|
|
6
6
|
return {
|
|
7
|
-
message: () =>
|
|
7
|
+
message: () => "expected ".concat(received, " to be an instance of URL"),
|
|
8
8
|
pass: false
|
|
9
9
|
};
|
|
10
10
|
}
|
|
@@ -13,7 +13,7 @@ expect.extend({
|
|
|
13
13
|
received.hash = received.hash;
|
|
14
14
|
expected.hash = expected.hash;
|
|
15
15
|
return {
|
|
16
|
-
message: () =>
|
|
16
|
+
message: () => "expected ".concat(received.href, " to be ").concat(expected.href),
|
|
17
17
|
pass: received.href === expected.href
|
|
18
18
|
};
|
|
19
19
|
}
|
|
@@ -143,7 +143,7 @@ describe("parseLocation", () => {
|
|
|
143
143
|
symbol: Symbol(),
|
|
144
144
|
fn: async () => "",
|
|
145
145
|
obj: { a: 10 },
|
|
146
|
-
big:
|
|
146
|
+
big: /* @__PURE__ */ BigInt("12345678901234567891234567890123456789"),
|
|
147
147
|
a: Number.NaN,
|
|
148
148
|
b: "",
|
|
149
149
|
c: "0",
|
|
@@ -152,9 +152,9 @@ describe("parseLocation", () => {
|
|
|
152
152
|
}
|
|
153
153
|
},
|
|
154
154
|
base: "http://example.com",
|
|
155
|
-
expected:
|
|
155
|
+
expected: "http://example.com/products?symbol=Symbol()&fn=".concat(String(
|
|
156
156
|
async () => ""
|
|
157
|
-
)
|
|
157
|
+
), "&obj=").concat(String({}), "&big=12345678901234567891234567890123456789&b&c=0&d=0&e=1"),
|
|
158
158
|
description: "should ignore null, undefined, and NaN query parameters"
|
|
159
159
|
},
|
|
160
160
|
{
|
|
@@ -350,8 +350,8 @@ describe("normalizeURL more", () => {
|
|
|
350
350
|
"new/.././a/../../x/": "https://www.esmx.dev/a/b/x/"
|
|
351
351
|
}
|
|
352
352
|
})
|
|
353
|
-
)(
|
|
354
|
-
test.each(Object.entries(cases))(
|
|
353
|
+
)("base: $0", ([base, cases]) => {
|
|
354
|
+
test.each(Object.entries(cases))("input: $0", (input, expected) => {
|
|
355
355
|
const url = normalizeURL(input, new URL(base));
|
|
356
356
|
expect(url).toEqURL(expected);
|
|
357
357
|
const pathSuffix = "?a&b=1&c=2&a=&a=4&base=10#hash";
|
package/dist/matcher.mjs
CHANGED
|
@@ -40,5 +40,5 @@ function createRouteMatches(routes, base = "") {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
export function joinPathname(pathname, base = "") {
|
|
43
|
-
return "/" +
|
|
43
|
+
return "/" + "".concat(base, "/").concat(pathname).split("/").filter(Boolean).join("/");
|
|
44
44
|
}
|
package/dist/matcher.test.mjs
CHANGED
|
@@ -95,7 +95,7 @@ describe("joinPathname", () => {
|
|
|
95
95
|
const longSegment = "very-long-segment-name-that-could-cause-issues";
|
|
96
96
|
const base = Array(10).fill(longSegment).join("/");
|
|
97
97
|
const path = Array(10).fill(longSegment).join("/");
|
|
98
|
-
const expected =
|
|
98
|
+
const expected = "/".concat(base, "/").concat(path);
|
|
99
99
|
return [{ path, base, expected }];
|
|
100
100
|
}
|
|
101
101
|
},
|
|
@@ -203,7 +203,7 @@ describe("joinPathname", () => {
|
|
|
203
203
|
description: "Handling of special symbols and punctuation",
|
|
204
204
|
cases: [
|
|
205
205
|
{ path: "path!@#$%^&\\*()", base: "base!@#$%^&\\*()", expected: "/base!@#$%^&\\*()/path!@#$%^&\\*()" },
|
|
206
|
-
{ path:
|
|
206
|
+
{ path: "path\\[]{};:\"'<>\\?", base: "base\\[]{};:\"'<>\\?", expected: "/base\\[]{};:\"'<>\\?/path\\[]{};:\"'<>\\?" },
|
|
207
207
|
{ path: "path\\backslash", base: "base\\backslash\\", expected: "/base\\backslash\\/path\\backslash" }
|
|
208
208
|
]
|
|
209
209
|
},
|
|
@@ -501,7 +501,7 @@ describe("createMatcher", () => {
|
|
|
501
501
|
});
|
|
502
502
|
test("Chinese path parameters", () => {
|
|
503
503
|
const matcher = createMatcher([
|
|
504
|
-
{ path:
|
|
504
|
+
{ path: "/".concat(encodeURIComponent("\u5206\u7C7B"), "/:name") }
|
|
505
505
|
]);
|
|
506
506
|
const result = matcher(new URL("/\u5206\u7C7B/\u6280\u672F", BASE_URL), BASE_URL);
|
|
507
507
|
assert.equal(result.matches.length, 1);
|
|
@@ -568,7 +568,7 @@ describe("createMatcher", () => {
|
|
|
568
568
|
});
|
|
569
569
|
test.todo("Route matching performance verification", () => {
|
|
570
570
|
const routes = Array.from({ length: 1e3 }, (_, i) => ({
|
|
571
|
-
path:
|
|
571
|
+
path: "/route".concat(i, "/:id")
|
|
572
572
|
}));
|
|
573
573
|
routes.push({ path: "/target/:id" });
|
|
574
574
|
const matcher = createMatcher(routes);
|
|
@@ -939,7 +939,7 @@ describe("createMatcher", () => {
|
|
|
939
939
|
const routes = [];
|
|
940
940
|
for (let i = 0; i < 500; i++) {
|
|
941
941
|
routes.push({
|
|
942
|
-
path:
|
|
942
|
+
path: "/category".concat(i, "/:id"),
|
|
943
943
|
children: [
|
|
944
944
|
{
|
|
945
945
|
path: "subcategory/:subId"
|
package/dist/micro-app.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1
4
|
import { isBrowser, isPlainObject } from "./util.mjs";
|
|
2
5
|
export function resolveRootElement(rootConfig) {
|
|
3
6
|
let el = null;
|
|
@@ -8,7 +11,7 @@ export function resolveRootElement(rootConfig) {
|
|
|
8
11
|
try {
|
|
9
12
|
el = document.querySelector(rootConfig);
|
|
10
13
|
} catch (error) {
|
|
11
|
-
console.warn(
|
|
14
|
+
console.warn("Failed to resolve root element: ".concat(rootConfig));
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
17
|
if (el === null) {
|
|
@@ -17,9 +20,11 @@ export function resolveRootElement(rootConfig) {
|
|
|
17
20
|
return el;
|
|
18
21
|
}
|
|
19
22
|
export class MicroApp {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
constructor() {
|
|
24
|
+
__publicField(this, "app", null);
|
|
25
|
+
__publicField(this, "root", null);
|
|
26
|
+
__publicField(this, "_factory", null);
|
|
27
|
+
}
|
|
23
28
|
_update(router, force = false) {
|
|
24
29
|
const factory = this._getNextFactory(router);
|
|
25
30
|
if (!force && factory === this._factory) {
|
package/dist/navigation.d.ts
CHANGED
|
@@ -18,7 +18,9 @@ export declare class Navigation {
|
|
|
18
18
|
replace(data: any, url?: string | URL | null): RouteState;
|
|
19
19
|
pushHistoryState(data: any, url?: string | URL | null): void;
|
|
20
20
|
replaceHistoryState(data: any, url?: string | URL | null): void;
|
|
21
|
-
|
|
21
|
+
backHistoryState(): Promise<NavigationGoResult>;
|
|
22
|
+
private _go;
|
|
23
|
+
go(delta?: number): Promise<NavigationGoResult>;
|
|
22
24
|
forward(): Promise<NavigationGoResult>;
|
|
23
25
|
back(): Promise<NavigationGoResult>;
|
|
24
26
|
destroy(): void;
|
package/dist/navigation.mjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1
4
|
import { PAGE_ID } from "./increment-id.mjs";
|
|
2
5
|
import { RouterMode } from "./types.mjs";
|
|
3
6
|
const PAGE_ID_KEY = "__pageId__";
|
|
4
7
|
export class Navigation {
|
|
5
|
-
options;
|
|
6
|
-
_history;
|
|
7
|
-
_unSubscribePopState;
|
|
8
|
-
_promiseResolve = null;
|
|
9
8
|
constructor(options, onUpdated) {
|
|
9
|
+
__publicField(this, "options");
|
|
10
|
+
__publicField(this, "_history");
|
|
11
|
+
__publicField(this, "_unSubscribePopState");
|
|
12
|
+
__publicField(this, "_promiseResolve", null);
|
|
10
13
|
const history2 = options.mode === RouterMode.history ? window.history : new MemoryHistory();
|
|
11
14
|
const onPopStateChange = (url, state) => {
|
|
12
15
|
const dispatchEvent = this._promiseResolve || onUpdated;
|
|
@@ -50,7 +53,10 @@ export class Navigation {
|
|
|
50
53
|
replaceHistoryState(data, url) {
|
|
51
54
|
this._replace(history, data, url);
|
|
52
55
|
}
|
|
53
|
-
|
|
56
|
+
backHistoryState() {
|
|
57
|
+
return this._go(history, -1);
|
|
58
|
+
}
|
|
59
|
+
_go(history2, index) {
|
|
54
60
|
if (this._promiseResolve) {
|
|
55
61
|
return Promise.resolve(null);
|
|
56
62
|
}
|
|
@@ -61,9 +67,12 @@ export class Navigation {
|
|
|
61
67
|
resolve({ type: "success", url, state: state || {} });
|
|
62
68
|
};
|
|
63
69
|
setTimeout(this._promiseResolve, 80);
|
|
64
|
-
|
|
70
|
+
history2.go(index);
|
|
65
71
|
});
|
|
66
72
|
}
|
|
73
|
+
go(delta) {
|
|
74
|
+
return this._go(this._history, delta || 0);
|
|
75
|
+
}
|
|
67
76
|
forward() {
|
|
68
77
|
return this.go(1);
|
|
69
78
|
}
|
|
@@ -77,34 +86,35 @@ export class Navigation {
|
|
|
77
86
|
}
|
|
78
87
|
}
|
|
79
88
|
export class MemoryHistory {
|
|
80
|
-
|
|
81
|
-
|
|
89
|
+
constructor() {
|
|
90
|
+
__publicField(this, "_entries", []);
|
|
91
|
+
__publicField(this, "_index", -1);
|
|
92
|
+
__publicField(this, "_popStateCbs", /* @__PURE__ */ new Set());
|
|
93
|
+
__publicField(this, "scrollRestoration", "auto");
|
|
94
|
+
this.pushState(null, "", "/");
|
|
95
|
+
}
|
|
82
96
|
get _curEntry() {
|
|
83
97
|
const idx = this._index;
|
|
84
98
|
if (idx < 0 || idx >= this.length) return null;
|
|
85
99
|
return this._entries[idx];
|
|
86
100
|
}
|
|
87
|
-
_popStateCbs = /* @__PURE__ */ new Set();
|
|
88
|
-
scrollRestoration = "auto";
|
|
89
101
|
// Return null when no current entry to align with browser history.state behavior
|
|
90
102
|
// Browser history.state can be null when no state was provided
|
|
91
103
|
get state() {
|
|
92
|
-
var _a;
|
|
93
|
-
return ((_a = this._curEntry) == null ? void 0 : _a.state)
|
|
104
|
+
var _a, _b;
|
|
105
|
+
return (_b = (_a = this._curEntry) == null ? void 0 : _a.state) != null ? _b : null;
|
|
94
106
|
}
|
|
95
107
|
get url() {
|
|
96
|
-
var _a;
|
|
97
|
-
return ((_a = this._curEntry) == null ? void 0 : _a.url)
|
|
98
|
-
}
|
|
99
|
-
constructor() {
|
|
100
|
-
this.pushState(null, "", "/");
|
|
108
|
+
var _a, _b;
|
|
109
|
+
return (_b = (_a = this._curEntry) == null ? void 0 : _a.url) != null ? _b : "";
|
|
101
110
|
}
|
|
102
111
|
get length() {
|
|
103
112
|
return this._entries.length;
|
|
104
113
|
}
|
|
105
114
|
pushState(data, unused, url) {
|
|
115
|
+
var _a;
|
|
106
116
|
this._entries.splice(this._index + 1);
|
|
107
|
-
this._entries.push({ state: data, url: (url == null ? void 0 : url.toString())
|
|
117
|
+
this._entries.push({ state: data, url: (_a = url == null ? void 0 : url.toString()) != null ? _a : this.url });
|
|
108
118
|
this._index = this._entries.length - 1;
|
|
109
119
|
}
|
|
110
120
|
replaceState(data, unused, url) {
|
package/dist/options.mjs
CHANGED
|
@@ -13,7 +13,7 @@ function getBaseUrl(options) {
|
|
|
13
13
|
const host = req.headers["x-forwarded-host"] || req.headers.host || req.headers["x-real-ip"] || "localhost";
|
|
14
14
|
const port = req.headers["x-forwarded-port"];
|
|
15
15
|
const path = req.url || "";
|
|
16
|
-
sourceUrl =
|
|
16
|
+
sourceUrl = "".concat(protocol, "://").concat(host).concat(port ? ":".concat(port) : "").concat(path);
|
|
17
17
|
} else {
|
|
18
18
|
sourceUrl = "https://www.esmnext.com/";
|
|
19
19
|
}
|
|
@@ -22,7 +22,7 @@ function getBaseUrl(options) {
|
|
|
22
22
|
base = new URL(".", sourceUrl);
|
|
23
23
|
} catch (e) {
|
|
24
24
|
console.warn(
|
|
25
|
-
|
|
25
|
+
"Failed to parse base URL '".concat(sourceUrl, "', using default: https://www.esmnext.com/")
|
|
26
26
|
);
|
|
27
27
|
base = new URL("https://www.esmnext.com/");
|
|
28
28
|
}
|
|
@@ -30,8 +30,9 @@ function getBaseUrl(options) {
|
|
|
30
30
|
return base;
|
|
31
31
|
}
|
|
32
32
|
export function parsedOptions(options = {}) {
|
|
33
|
+
var _a, _b, _c, _d, _e, _f;
|
|
33
34
|
const base = getBaseUrl(options);
|
|
34
|
-
const routes = Array.from(options.routes
|
|
35
|
+
const routes = Array.from((_a = options.routes) != null ? _a : []);
|
|
35
36
|
return Object.freeze({
|
|
36
37
|
rootStyle: options.rootStyle || false,
|
|
37
38
|
root: options.root || "",
|
|
@@ -41,16 +42,16 @@ export function parsedOptions(options = {}) {
|
|
|
41
42
|
layer: options.layer || false,
|
|
42
43
|
zIndex: options.zIndex || 1e4,
|
|
43
44
|
base,
|
|
44
|
-
mode: isBrowser ? options.mode
|
|
45
|
+
mode: isBrowser ? (_b = options.mode) != null ? _b : RouterMode.history : RouterMode.memory,
|
|
45
46
|
routes,
|
|
46
47
|
apps: typeof options.apps === "function" ? options.apps : Object.assign({}, options.apps),
|
|
47
48
|
matcher: createMatcher(routes),
|
|
48
|
-
normalizeURL: options.normalizeURL
|
|
49
|
-
fallback: options.fallback
|
|
50
|
-
handleBackBoundary: options.handleBackBoundary
|
|
51
|
-
}
|
|
52
|
-
handleLayerClose: options.handleLayerClose
|
|
53
|
-
}
|
|
49
|
+
normalizeURL: (_c = options.normalizeURL) != null ? _c : (url) => url,
|
|
50
|
+
fallback: (_d = options.fallback) != null ? _d : fallback,
|
|
51
|
+
handleBackBoundary: (_e = options.handleBackBoundary) != null ? _e : () => {
|
|
52
|
+
},
|
|
53
|
+
handleLayerClose: (_f = options.handleLayerClose) != null ? _f : () => {
|
|
54
|
+
}
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
export function fallback(to, from, router) {
|
|
@@ -62,7 +63,7 @@ export function fallback(to, from, router) {
|
|
|
62
63
|
statusCode = to.statusCode;
|
|
63
64
|
} else if (to.statusCode) {
|
|
64
65
|
console.warn(
|
|
65
|
-
|
|
66
|
+
"Invalid redirect status code ".concat(to.statusCode, ", using default 302")
|
|
66
67
|
);
|
|
67
68
|
}
|
|
68
69
|
router.res.statusCode = statusCode;
|
|
@@ -80,7 +81,7 @@ export function fallback(to, from, router) {
|
|
|
80
81
|
newWindow.opener = null;
|
|
81
82
|
}
|
|
82
83
|
return newWindow;
|
|
83
|
-
} catch {
|
|
84
|
+
} catch (e) {
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
location.href = href;
|
package/dist/route-task.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1
4
|
import {
|
|
2
5
|
RouteNavigationAbortedError,
|
|
3
6
|
RouteSelfRedirectionError,
|
|
@@ -7,7 +10,9 @@ import {
|
|
|
7
10
|
import { Route } from "./route.mjs";
|
|
8
11
|
import { isUrlEqual, isValidConfirmHookResult } from "./util.mjs";
|
|
9
12
|
export class RouteTaskController {
|
|
10
|
-
|
|
13
|
+
constructor() {
|
|
14
|
+
__publicField(this, "_aborted", false);
|
|
15
|
+
}
|
|
11
16
|
/**
|
|
12
17
|
* Aborts the current task.
|
|
13
18
|
*/
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1
4
|
import { Route } from "./route.mjs";
|
|
2
5
|
import {
|
|
3
6
|
RouteTaskController,
|
|
@@ -31,9 +34,9 @@ export const ROUTE_TRANSITION_HOOKS = {
|
|
|
31
34
|
try {
|
|
32
35
|
const result = await asyncComponent();
|
|
33
36
|
matched.component = result;
|
|
34
|
-
} catch {
|
|
37
|
+
} catch (e) {
|
|
35
38
|
throw new Error(
|
|
36
|
-
|
|
39
|
+
"Async component '".concat(matched.compilePath, "' is not a valid component.")
|
|
37
40
|
);
|
|
38
41
|
}
|
|
39
42
|
}
|
|
@@ -237,16 +240,16 @@ const ROUTE_TRANSITION_PIPELINE = {
|
|
|
237
240
|
]
|
|
238
241
|
};
|
|
239
242
|
export class RouteTransition {
|
|
240
|
-
router;
|
|
241
|
-
route = null;
|
|
242
|
-
// Task controller for the current transition.
|
|
243
|
-
_controller = null;
|
|
244
|
-
// Guard arrays, responsible for storing navigation guards.
|
|
245
|
-
guards = {
|
|
246
|
-
beforeEach: [],
|
|
247
|
-
afterEach: []
|
|
248
|
-
};
|
|
249
243
|
constructor(router) {
|
|
244
|
+
__publicField(this, "router");
|
|
245
|
+
__publicField(this, "route", null);
|
|
246
|
+
// Task controller for the current transition.
|
|
247
|
+
__publicField(this, "_controller", null);
|
|
248
|
+
// Guard arrays, responsible for storing navigation guards.
|
|
249
|
+
__publicField(this, "guards", {
|
|
250
|
+
beforeEach: [],
|
|
251
|
+
afterEach: []
|
|
252
|
+
});
|
|
250
253
|
this.router = router;
|
|
251
254
|
}
|
|
252
255
|
beforeEach(guard) {
|
|
@@ -267,13 +270,14 @@ export class RouteTransition {
|
|
|
267
270
|
this._controller = null;
|
|
268
271
|
}
|
|
269
272
|
async to(toType, toInput) {
|
|
270
|
-
|
|
273
|
+
var _a, _b, _c;
|
|
274
|
+
const from = (_b = (_a = this.route) == null ? void 0 : _a.clone()) != null ? _b : null;
|
|
271
275
|
const to = await this._runTask(
|
|
272
276
|
new Route({
|
|
273
277
|
options: this.router.parsedOptions,
|
|
274
278
|
toType,
|
|
275
279
|
toInput,
|
|
276
|
-
from: (from == null ? void 0 : from.url)
|
|
280
|
+
from: (_c = from == null ? void 0 : from.url) != null ? _c : null
|
|
277
281
|
}),
|
|
278
282
|
from
|
|
279
283
|
);
|
|
@@ -62,7 +62,7 @@ describe("Route Transition Tests", () => {
|
|
|
62
62
|
test("should handle concurrent navigation attempts", async () => {
|
|
63
63
|
const promises = Array.from(
|
|
64
64
|
{ length: 5 },
|
|
65
|
-
(_, i) => router.push(
|
|
65
|
+
(_, i) => router.push("/user/".concat(i + 1)).catch((err) => err)
|
|
66
66
|
);
|
|
67
67
|
const results = await Promise.all(promises);
|
|
68
68
|
const successResults = results.filter((r) => !(r instanceof Error));
|
package/dist/route.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1
4
|
import { parseLocation } from "./location.mjs";
|
|
2
5
|
import { parsedOptions } from "./options.mjs";
|
|
3
6
|
import {
|
|
@@ -39,35 +42,35 @@ export function applyRouteParams(match, toInput, base, to) {
|
|
|
39
42
|
Object.assign(match.params, toInput.params);
|
|
40
43
|
}
|
|
41
44
|
export class Route {
|
|
42
|
-
// Private fields for handle validation
|
|
43
|
-
_handled = false;
|
|
44
|
-
_handle = null;
|
|
45
|
-
_handleResult = null;
|
|
46
|
-
_options;
|
|
47
|
-
// Public properties
|
|
48
|
-
statusCode = null;
|
|
49
|
-
state;
|
|
50
|
-
keepScrollPosition;
|
|
51
|
-
/** Custom confirm handler that overrides default route-transition confirm logic */
|
|
52
|
-
confirm;
|
|
53
|
-
/** Layer configuration for layer routes */
|
|
54
|
-
layer;
|
|
55
|
-
// Read-only properties
|
|
56
|
-
type;
|
|
57
|
-
req;
|
|
58
|
-
res;
|
|
59
|
-
context;
|
|
60
|
-
url;
|
|
61
|
-
path;
|
|
62
|
-
fullPath;
|
|
63
|
-
hash;
|
|
64
|
-
params = {};
|
|
65
|
-
query = {};
|
|
66
|
-
queryArray = {};
|
|
67
|
-
meta;
|
|
68
|
-
matched;
|
|
69
|
-
config;
|
|
70
45
|
constructor(routeOptions = {}) {
|
|
46
|
+
// Private fields for handle validation
|
|
47
|
+
__publicField(this, "_handled", false);
|
|
48
|
+
__publicField(this, "_handle", null);
|
|
49
|
+
__publicField(this, "_handleResult", null);
|
|
50
|
+
__publicField(this, "_options");
|
|
51
|
+
// Public properties
|
|
52
|
+
__publicField(this, "statusCode", null);
|
|
53
|
+
__publicField(this, "state");
|
|
54
|
+
__publicField(this, "keepScrollPosition");
|
|
55
|
+
/** Custom confirm handler that overrides default route-transition confirm logic */
|
|
56
|
+
__publicField(this, "confirm");
|
|
57
|
+
/** Layer configuration for layer routes */
|
|
58
|
+
__publicField(this, "layer");
|
|
59
|
+
// Read-only properties
|
|
60
|
+
__publicField(this, "type");
|
|
61
|
+
__publicField(this, "req");
|
|
62
|
+
__publicField(this, "res");
|
|
63
|
+
__publicField(this, "context");
|
|
64
|
+
__publicField(this, "url");
|
|
65
|
+
__publicField(this, "path");
|
|
66
|
+
__publicField(this, "fullPath");
|
|
67
|
+
__publicField(this, "hash");
|
|
68
|
+
__publicField(this, "params", {});
|
|
69
|
+
__publicField(this, "query", {});
|
|
70
|
+
__publicField(this, "queryArray", {});
|
|
71
|
+
__publicField(this, "meta");
|
|
72
|
+
__publicField(this, "matched");
|
|
73
|
+
__publicField(this, "config");
|
|
71
74
|
var _a;
|
|
72
75
|
const {
|
|
73
76
|
toType = RouteType.push,
|
package/dist/route.test.mjs
CHANGED
|
@@ -892,9 +892,9 @@ describe("Route Class Complete Test Suite", () => {
|
|
|
892
892
|
const options = createOptions();
|
|
893
893
|
const queryParams = Array.from(
|
|
894
894
|
{ length: 100 },
|
|
895
|
-
(_, i) =>
|
|
895
|
+
(_, i) => "param".concat(i, "=value").concat(i)
|
|
896
896
|
).join("&");
|
|
897
|
-
const path =
|
|
897
|
+
const path = "/test?".concat(queryParams);
|
|
898
898
|
const route = new Route({
|
|
899
899
|
options,
|
|
900
900
|
toType: RouteType.push,
|
|
@@ -1081,7 +1081,7 @@ describe("Route Class Complete Test Suite", () => {
|
|
|
1081
1081
|
new Route({
|
|
1082
1082
|
options,
|
|
1083
1083
|
toType: RouteType.push,
|
|
1084
|
-
toInput:
|
|
1084
|
+
toInput: "/users/".concat(i)
|
|
1085
1085
|
});
|
|
1086
1086
|
}
|
|
1087
1087
|
const endTime = performance.now();
|
|
@@ -1097,7 +1097,7 @@ describe("Route Class Complete Test Suite", () => {
|
|
|
1097
1097
|
});
|
|
1098
1098
|
const startTime = performance.now();
|
|
1099
1099
|
for (let i = 0; i < 1e3; i++) {
|
|
1100
|
-
route.state[
|
|
1100
|
+
route.state["key".concat(i)] = "value".concat(i);
|
|
1101
1101
|
}
|
|
1102
1102
|
const endTime = performance.now();
|
|
1103
1103
|
const duration = endTime - startTime;
|
|
@@ -10,7 +10,7 @@ describe("Router.back Tests", () => {
|
|
|
10
10
|
mode: RouterMode.memory,
|
|
11
11
|
base: new URL("http://localhost:3000/"),
|
|
12
12
|
fallback: (to, from) => {
|
|
13
|
-
executionLog.push(
|
|
13
|
+
executionLog.push("location-handler-".concat(to.path));
|
|
14
14
|
},
|
|
15
15
|
routes: [
|
|
16
16
|
{
|
|
@@ -10,7 +10,7 @@ describe("Router.forward Tests", () => {
|
|
|
10
10
|
mode: RouterMode.memory,
|
|
11
11
|
base: new URL("http://localhost:3000/"),
|
|
12
12
|
fallback: (to, from) => {
|
|
13
|
-
executionLog.push(
|
|
13
|
+
executionLog.push("location-handler-".concat(to.path));
|
|
14
14
|
},
|
|
15
15
|
routes: [
|
|
16
16
|
{
|