@esportsplus/routing 0.0.38 → 0.0.39
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/build/browser.js +17 -12
- package/package.json +1 -1
- package/src/browser.ts +24 -17
package/build/browser.js
CHANGED
|
@@ -10,18 +10,23 @@ function forward() {
|
|
|
10
10
|
window.history.forward();
|
|
11
11
|
}
|
|
12
12
|
function href() {
|
|
13
|
-
let
|
|
14
|
-
return {
|
|
13
|
+
let data = new URL(window.location?.href || ''), path = data.hash ? data.hash.slice(1).split('?') : ['/', ''], request = {
|
|
15
14
|
data: {},
|
|
16
|
-
href,
|
|
17
|
-
hostname,
|
|
15
|
+
href: data.href,
|
|
16
|
+
hostname: data.hostname,
|
|
18
17
|
method: 'GET',
|
|
19
|
-
origin,
|
|
18
|
+
origin: data.origin,
|
|
20
19
|
path: path[0],
|
|
21
|
-
port,
|
|
22
|
-
protocol,
|
|
23
|
-
query:
|
|
20
|
+
port: data.port,
|
|
21
|
+
protocol: data.protocol,
|
|
22
|
+
query: {}
|
|
24
23
|
};
|
|
24
|
+
if (path[1]) {
|
|
25
|
+
for (let [key, value] of (new URLSearchParams(path[1])).entries()) {
|
|
26
|
+
request.query[key] = value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return request;
|
|
25
30
|
}
|
|
26
31
|
function match(request, router, subdomain) {
|
|
27
32
|
if (router.subdomains !== null) {
|
|
@@ -51,8 +56,8 @@ function middleware(request, router) {
|
|
|
51
56
|
host.match = (fallback, scheduler, subdomain) => {
|
|
52
57
|
let state = reactive({
|
|
53
58
|
parameters: undefined,
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
root: undefined,
|
|
60
|
+
route: undefined
|
|
56
61
|
});
|
|
57
62
|
if (fallback === undefined) {
|
|
58
63
|
throw new Error('Middleware: fallback route does not exist');
|
|
@@ -70,10 +75,10 @@ function middleware(request, router) {
|
|
|
70
75
|
if (state.root !== undefined) {
|
|
71
76
|
state.root.dispose();
|
|
72
77
|
}
|
|
73
|
-
return root((
|
|
78
|
+
return root((root) => {
|
|
74
79
|
request.data.parameters = state.parameters;
|
|
75
80
|
request.data.route = state.route;
|
|
76
|
-
state.root =
|
|
81
|
+
state.root = root;
|
|
77
82
|
return next(request);
|
|
78
83
|
}, scheduler);
|
|
79
84
|
}}`;
|
package/package.json
CHANGED
package/src/browser.ts
CHANGED
|
@@ -17,20 +17,27 @@ function forward() {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function href<T>(): Request<T> {
|
|
20
|
-
let
|
|
21
|
-
path = hash ? hash.slice(1).split('?') : ['/', '']
|
|
20
|
+
let data = new URL( window.location?.href || '' ),
|
|
21
|
+
path = data.hash ? data.hash.slice(1).split('?') : ['/', ''],
|
|
22
|
+
request: Request<T> = {
|
|
23
|
+
data: {},
|
|
24
|
+
href: data.href,
|
|
25
|
+
hostname: data.hostname,
|
|
26
|
+
method: 'GET',
|
|
27
|
+
origin: data.origin,
|
|
28
|
+
path: path[0],
|
|
29
|
+
port: data.port,
|
|
30
|
+
protocol: data.protocol,
|
|
31
|
+
query: {}
|
|
32
|
+
};
|
|
22
33
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
port,
|
|
31
|
-
protocol,
|
|
32
|
-
query: path[1] ? Object.fromEntries( (new URLSearchParams(path[1])).entries() ) : {},
|
|
33
|
-
};
|
|
34
|
+
if (path[1]) {
|
|
35
|
+
for (let [key, value] of (new URLSearchParams(path[1])).entries()) {
|
|
36
|
+
request.query[key] = value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return request;
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
function match<T>(request: Request<T>, router: Router<T>, subdomain?: string) {
|
|
@@ -68,8 +75,8 @@ function middleware<T>(request: Request<T>, router: Router<T>) {
|
|
|
68
75
|
host.match = (fallback: Route<T>, scheduler: Scheduler, subdomain?: string) => {
|
|
69
76
|
let state = reactive<ReturnType<typeof router.match> & { root?: Root }>({
|
|
70
77
|
parameters: undefined,
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
root: undefined,
|
|
79
|
+
route: undefined
|
|
73
80
|
});
|
|
74
81
|
|
|
75
82
|
if (fallback === undefined) {
|
|
@@ -93,11 +100,11 @@ function middleware<T>(request: Request<T>, router: Router<T>) {
|
|
|
93
100
|
state.root.dispose();
|
|
94
101
|
}
|
|
95
102
|
|
|
96
|
-
return root((
|
|
103
|
+
return root((root) => {
|
|
97
104
|
request.data.parameters = state.parameters;
|
|
98
105
|
request.data.route = state.route;
|
|
99
106
|
|
|
100
|
-
state.root =
|
|
107
|
+
state.root = root;
|
|
101
108
|
|
|
102
109
|
return next(request);
|
|
103
110
|
}, scheduler);
|