@solidjs/router 0.14.7 → 0.14.9
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/README.md +1 -1
- package/dist/components.jsx +1 -1
- package/dist/data/cache.js +1 -1
- package/dist/data/events.js +17 -35
- package/dist/data/response.js +3 -3
- package/dist/index.js +43 -52
- package/dist/routing.d.ts +2 -3
- package/dist/routing.js +15 -9
- package/dist/types.d.ts +3 -3
- package/package.json +5 -5
package/README.md
CHANGED
package/dist/components.jsx
CHANGED
|
@@ -19,7 +19,7 @@ export function A(props) {
|
|
|
19
19
|
if (to_ === undefined)
|
|
20
20
|
return [false, false];
|
|
21
21
|
const path = normalizePath(to_.split(/[?#]/, 1)[0]).toLowerCase();
|
|
22
|
-
const loc = normalizePath(location.pathname).toLowerCase();
|
|
22
|
+
const loc = decodeURI(normalizePath(location.pathname).toLowerCase());
|
|
23
23
|
return [props.end ? path === loc : loc.startsWith(path + "/") || loc === path, path === loc];
|
|
24
24
|
});
|
|
25
25
|
return (<a {...rest} href={href() || props.href} state={JSON.stringify(props.state)} classList={{
|
package/dist/data/cache.js
CHANGED
package/dist/data/events.js
CHANGED
|
@@ -6,7 +6,8 @@ export function setupNativeEvents(preload = true, explicitLinks = false, actionB
|
|
|
6
6
|
return (router) => {
|
|
7
7
|
const basePath = router.base.path();
|
|
8
8
|
const navigateFromRoute = router.navigatorFactory(router.base);
|
|
9
|
-
let preloadTimeout
|
|
9
|
+
let preloadTimeout;
|
|
10
|
+
let lastElement;
|
|
10
11
|
function isSvg(el) {
|
|
11
12
|
return el.namespaceURI === "http://www.w3.org/2000/svg";
|
|
12
13
|
}
|
|
@@ -57,39 +58,22 @@ export function setupNativeEvents(preload = true, explicitLinks = false, actionB
|
|
|
57
58
|
if (!res)
|
|
58
59
|
return;
|
|
59
60
|
const [a, url] = res;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
if (!preloadTimeout[url.pathname])
|
|
64
|
-
router.preloadRoute(url, { preloadData: a.getAttribute("preload") !== "false" });
|
|
61
|
+
transformUrl && (url.pathname = transformUrl(url.pathname));
|
|
62
|
+
router.preloadRoute(url, a.getAttribute("preload") !== "false");
|
|
65
63
|
}
|
|
66
|
-
function
|
|
64
|
+
function handleAnchorMove(evt) {
|
|
65
|
+
clearTimeout(preloadTimeout);
|
|
67
66
|
const res = handleAnchor(evt);
|
|
68
67
|
if (!res)
|
|
69
|
-
return;
|
|
68
|
+
return lastElement = null;
|
|
70
69
|
const [a, url] = res;
|
|
71
|
-
if (
|
|
72
|
-
url.pathname = transformUrl(url.pathname);
|
|
73
|
-
}
|
|
74
|
-
if (preloadTimeout[url.pathname])
|
|
70
|
+
if (lastElement === a)
|
|
75
71
|
return;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
function handleAnchorOut(evt) {
|
|
82
|
-
const res = handleAnchor(evt);
|
|
83
|
-
if (!res)
|
|
84
|
-
return;
|
|
85
|
-
const [, url] = res;
|
|
86
|
-
if (typeof transformUrl === "function") {
|
|
87
|
-
url.pathname = transformUrl(url.pathname);
|
|
88
|
-
}
|
|
89
|
-
if (preloadTimeout[url.pathname]) {
|
|
90
|
-
clearTimeout(preloadTimeout[url.pathname]);
|
|
91
|
-
delete preloadTimeout[url.pathname];
|
|
92
|
-
}
|
|
72
|
+
transformUrl && (url.pathname = transformUrl(url.pathname));
|
|
73
|
+
preloadTimeout = setTimeout(() => {
|
|
74
|
+
router.preloadRoute(url, a.getAttribute("preload") !== "false");
|
|
75
|
+
lastElement = a;
|
|
76
|
+
}, 20);
|
|
93
77
|
}
|
|
94
78
|
function handleFormSubmit(evt) {
|
|
95
79
|
if (evt.defaultPrevented)
|
|
@@ -121,17 +105,15 @@ export function setupNativeEvents(preload = true, explicitLinks = false, actionB
|
|
|
121
105
|
delegateEvents(["click", "submit"]);
|
|
122
106
|
document.addEventListener("click", handleAnchorClick);
|
|
123
107
|
if (preload) {
|
|
124
|
-
document.addEventListener("
|
|
125
|
-
document.addEventListener("
|
|
126
|
-
document.addEventListener("
|
|
127
|
-
document.addEventListener("touchstart", handleAnchorPreload);
|
|
108
|
+
document.addEventListener("mousemove", handleAnchorMove, { passive: true });
|
|
109
|
+
document.addEventListener("focusin", handleAnchorPreload, { passive: true });
|
|
110
|
+
document.addEventListener("touchstart", handleAnchorPreload, { passive: true });
|
|
128
111
|
}
|
|
129
112
|
document.addEventListener("submit", handleFormSubmit);
|
|
130
113
|
onCleanup(() => {
|
|
131
114
|
document.removeEventListener("click", handleAnchorClick);
|
|
132
115
|
if (preload) {
|
|
133
|
-
document.removeEventListener("
|
|
134
|
-
document.removeEventListener("mouseout", handleAnchorOut);
|
|
116
|
+
document.removeEventListener("mousemove", handleAnchorMove);
|
|
135
117
|
document.removeEventListener("focusin", handleAnchorPreload);
|
|
136
118
|
document.removeEventListener("touchstart", handleAnchorPreload);
|
|
137
119
|
}
|
package/dist/data/response.js
CHANGED
|
@@ -12,7 +12,7 @@ export function redirect(url, init = 302) {
|
|
|
12
12
|
}
|
|
13
13
|
const headers = new Headers(responseInit.headers);
|
|
14
14
|
headers.set("Location", url);
|
|
15
|
-
revalidate && headers.set("X-Revalidate", revalidate.toString());
|
|
15
|
+
revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
|
|
16
16
|
const response = new Response(null, {
|
|
17
17
|
...responseInit,
|
|
18
18
|
headers: headers
|
|
@@ -22,7 +22,7 @@ export function redirect(url, init = 302) {
|
|
|
22
22
|
export function reload(init = {}) {
|
|
23
23
|
const { revalidate, ...responseInit } = init;
|
|
24
24
|
const headers = new Headers(responseInit.headers);
|
|
25
|
-
revalidate && headers.set("X-Revalidate", revalidate.toString());
|
|
25
|
+
revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
|
|
26
26
|
return new Response(null, {
|
|
27
27
|
...responseInit,
|
|
28
28
|
headers
|
|
@@ -31,7 +31,7 @@ export function reload(init = {}) {
|
|
|
31
31
|
export function json(data, init = {}) {
|
|
32
32
|
const { revalidate, ...responseInit } = init;
|
|
33
33
|
const headers = new Headers(responseInit.headers);
|
|
34
|
-
revalidate && headers.set("X-Revalidate", revalidate.toString());
|
|
34
|
+
revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
|
|
35
35
|
headers.set("Content-Type", "application/json");
|
|
36
36
|
const response = new Response(JSON.stringify(data), {
|
|
37
37
|
...responseInit,
|
package/dist/index.js
CHANGED
|
@@ -244,7 +244,10 @@ const useHref = to => {
|
|
|
244
244
|
const useNavigate = () => useRouter().navigatorFactory();
|
|
245
245
|
const useLocation = () => useRouter().location;
|
|
246
246
|
const useIsRouting = () => useRouter().isRouting;
|
|
247
|
-
const usePreloadRoute = () =>
|
|
247
|
+
const usePreloadRoute = () => {
|
|
248
|
+
const pre = useRouter().preloadRoute;
|
|
249
|
+
return (url, options = {}) => pre(url instanceof URL ? url : new URL(url, mockBase), options.preloadData);
|
|
250
|
+
};
|
|
248
251
|
const useMatch = (path, matchFilters) => {
|
|
249
252
|
const location = useLocation();
|
|
250
253
|
const matchers = createMemo(() => expandOptionals(path()).map(path => createMatcher(path, undefined, matchFilters)));
|
|
@@ -367,7 +370,7 @@ function getRouteMatches(branches, location) {
|
|
|
367
370
|
}
|
|
368
371
|
return [];
|
|
369
372
|
}
|
|
370
|
-
function createLocation(path, state) {
|
|
373
|
+
function createLocation(path, state, queryWrapper) {
|
|
371
374
|
const origin = new URL(mockBase);
|
|
372
375
|
const url = createMemo(prev => {
|
|
373
376
|
const path_ = path();
|
|
@@ -384,6 +387,7 @@ function createLocation(path, state) {
|
|
|
384
387
|
const search = createMemo(() => url().search, true);
|
|
385
388
|
const hash = createMemo(() => url().hash);
|
|
386
389
|
const key = () => "";
|
|
390
|
+
const queryFn = on(search, () => extractSearchParams(url()));
|
|
387
391
|
return {
|
|
388
392
|
get pathname() {
|
|
389
393
|
return pathname();
|
|
@@ -400,7 +404,7 @@ function createLocation(path, state) {
|
|
|
400
404
|
get key() {
|
|
401
405
|
return key();
|
|
402
406
|
},
|
|
403
|
-
query:
|
|
407
|
+
query: queryWrapper ? queryWrapper(queryFn) : createMemoObject(queryFn)
|
|
404
408
|
};
|
|
405
409
|
}
|
|
406
410
|
let intent;
|
|
@@ -463,7 +467,7 @@ function createRouterContext(integration, branches, getContext, options = {}) {
|
|
|
463
467
|
};
|
|
464
468
|
const [reference, setReference] = createSignal(source().value);
|
|
465
469
|
const [state, setState] = createSignal(source().state);
|
|
466
|
-
const location = createLocation(reference, state);
|
|
470
|
+
const location = createLocation(reference, state, utils.queryWrapper);
|
|
467
471
|
const referrers = [];
|
|
468
472
|
const submissions = createSignal(isServer ? initFromFlash() : []);
|
|
469
473
|
const matches = createMemo(() => {
|
|
@@ -472,14 +476,15 @@ function createRouterContext(integration, branches, getContext, options = {}) {
|
|
|
472
476
|
}
|
|
473
477
|
return getRouteMatches(branches(), location.pathname);
|
|
474
478
|
});
|
|
475
|
-
const
|
|
479
|
+
const buildParams = () => {
|
|
476
480
|
const m = matches();
|
|
477
481
|
const params = {};
|
|
478
482
|
for (let i = 0; i < m.length; i++) {
|
|
479
483
|
Object.assign(params, m[i].params);
|
|
480
484
|
}
|
|
481
485
|
return params;
|
|
482
|
-
}
|
|
486
|
+
};
|
|
487
|
+
const params = utils.paramsWrapper ? utils.paramsWrapper(buildParams, branches) : createMemoObject(buildParams);
|
|
483
488
|
const baseRoute = {
|
|
484
489
|
pattern: basePath,
|
|
485
490
|
path: () => basePath,
|
|
@@ -583,7 +588,7 @@ function createRouterContext(integration, branches, getContext, options = {}) {
|
|
|
583
588
|
referrers.length = 0;
|
|
584
589
|
}
|
|
585
590
|
}
|
|
586
|
-
function preloadRoute(url,
|
|
591
|
+
function preloadRoute(url, preloadData) {
|
|
587
592
|
const matches = getRouteMatches(branches(), url.pathname);
|
|
588
593
|
const prevIntent = intent;
|
|
589
594
|
intent = "preload";
|
|
@@ -597,7 +602,7 @@ function createRouterContext(integration, branches, getContext, options = {}) {
|
|
|
597
602
|
preload
|
|
598
603
|
} = route;
|
|
599
604
|
inPreloadFn = true;
|
|
600
|
-
|
|
605
|
+
preloadData && preload && runWithOwner(getContext(), () => preload({
|
|
601
606
|
params,
|
|
602
607
|
location: {
|
|
603
608
|
pathname: url.pathname,
|
|
@@ -1030,7 +1035,7 @@ cache.set = (key, value) => {
|
|
|
1030
1035
|
cache.clear = () => getCache().clear();
|
|
1031
1036
|
function matchKey(key, keys) {
|
|
1032
1037
|
for (let k of keys) {
|
|
1033
|
-
if (key.startsWith(k)) return true;
|
|
1038
|
+
if (k && key.startsWith(k)) return true;
|
|
1034
1039
|
}
|
|
1035
1040
|
return false;
|
|
1036
1041
|
}
|
|
@@ -1186,7 +1191,8 @@ function setupNativeEvents(preload = true, explicitLinks = false, actionBase = "
|
|
|
1186
1191
|
return router => {
|
|
1187
1192
|
const basePath = router.base.path();
|
|
1188
1193
|
const navigateFromRoute = router.navigatorFactory(router.base);
|
|
1189
|
-
let preloadTimeout
|
|
1194
|
+
let preloadTimeout;
|
|
1195
|
+
let lastElement;
|
|
1190
1196
|
function isSvg(el) {
|
|
1191
1197
|
return el.namespaceURI === "http://www.w3.org/2000/svg";
|
|
1192
1198
|
}
|
|
@@ -1222,39 +1228,20 @@ function setupNativeEvents(preload = true, explicitLinks = false, actionBase = "
|
|
|
1222
1228
|
const res = handleAnchor(evt);
|
|
1223
1229
|
if (!res) return;
|
|
1224
1230
|
const [a, url] = res;
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
}
|
|
1228
|
-
if (!preloadTimeout[url.pathname]) router.preloadRoute(url, {
|
|
1229
|
-
preloadData: a.getAttribute("preload") !== "false"
|
|
1230
|
-
});
|
|
1231
|
+
transformUrl && (url.pathname = transformUrl(url.pathname));
|
|
1232
|
+
router.preloadRoute(url, a.getAttribute("preload") !== "false");
|
|
1231
1233
|
}
|
|
1232
|
-
function
|
|
1234
|
+
function handleAnchorMove(evt) {
|
|
1235
|
+
clearTimeout(preloadTimeout);
|
|
1233
1236
|
const res = handleAnchor(evt);
|
|
1234
|
-
if (!res) return;
|
|
1237
|
+
if (!res) return lastElement = null;
|
|
1235
1238
|
const [a, url] = res;
|
|
1236
|
-
if (
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
preloadData: a.getAttribute("preload") !== "false"
|
|
1243
|
-
});
|
|
1244
|
-
delete preloadTimeout[url.pathname];
|
|
1245
|
-
}, 200);
|
|
1246
|
-
}
|
|
1247
|
-
function handleAnchorOut(evt) {
|
|
1248
|
-
const res = handleAnchor(evt);
|
|
1249
|
-
if (!res) return;
|
|
1250
|
-
const [, url] = res;
|
|
1251
|
-
if (typeof transformUrl === "function") {
|
|
1252
|
-
url.pathname = transformUrl(url.pathname);
|
|
1253
|
-
}
|
|
1254
|
-
if (preloadTimeout[url.pathname]) {
|
|
1255
|
-
clearTimeout(preloadTimeout[url.pathname]);
|
|
1256
|
-
delete preloadTimeout[url.pathname];
|
|
1257
|
-
}
|
|
1239
|
+
if (lastElement === a) return;
|
|
1240
|
+
transformUrl && (url.pathname = transformUrl(url.pathname));
|
|
1241
|
+
preloadTimeout = setTimeout(() => {
|
|
1242
|
+
router.preloadRoute(url, a.getAttribute("preload") !== "false");
|
|
1243
|
+
lastElement = a;
|
|
1244
|
+
}, 20);
|
|
1258
1245
|
}
|
|
1259
1246
|
function handleFormSubmit(evt) {
|
|
1260
1247
|
if (evt.defaultPrevented) return;
|
|
@@ -1282,17 +1269,21 @@ function setupNativeEvents(preload = true, explicitLinks = false, actionBase = "
|
|
|
1282
1269
|
delegateEvents(["click", "submit"]);
|
|
1283
1270
|
document.addEventListener("click", handleAnchorClick);
|
|
1284
1271
|
if (preload) {
|
|
1285
|
-
document.addEventListener("
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
document.addEventListener("
|
|
1272
|
+
document.addEventListener("mousemove", handleAnchorMove, {
|
|
1273
|
+
passive: true
|
|
1274
|
+
});
|
|
1275
|
+
document.addEventListener("focusin", handleAnchorPreload, {
|
|
1276
|
+
passive: true
|
|
1277
|
+
});
|
|
1278
|
+
document.addEventListener("touchstart", handleAnchorPreload, {
|
|
1279
|
+
passive: true
|
|
1280
|
+
});
|
|
1289
1281
|
}
|
|
1290
1282
|
document.addEventListener("submit", handleFormSubmit);
|
|
1291
1283
|
onCleanup(() => {
|
|
1292
1284
|
document.removeEventListener("click", handleAnchorClick);
|
|
1293
1285
|
if (preload) {
|
|
1294
|
-
document.removeEventListener("
|
|
1295
|
-
document.removeEventListener("mouseout", handleAnchorOut);
|
|
1286
|
+
document.removeEventListener("mousemove", handleAnchorMove);
|
|
1296
1287
|
document.removeEventListener("focusin", handleAnchorPreload);
|
|
1297
1288
|
document.removeEventListener("touchstart", handleAnchorPreload);
|
|
1298
1289
|
}
|
|
@@ -1448,7 +1439,7 @@ function MemoryRouter(props) {
|
|
|
1448
1439
|
})(props);
|
|
1449
1440
|
}
|
|
1450
1441
|
|
|
1451
|
-
|
|
1442
|
+
var _tmpl$ = /*#__PURE__*/template(`<a>`);
|
|
1452
1443
|
function A(props) {
|
|
1453
1444
|
props = mergeProps({
|
|
1454
1445
|
inactiveClass: "inactive",
|
|
@@ -1462,11 +1453,11 @@ function A(props) {
|
|
|
1462
1453
|
const to_ = to();
|
|
1463
1454
|
if (to_ === undefined) return [false, false];
|
|
1464
1455
|
const path = normalizePath(to_.split(/[?#]/, 1)[0]).toLowerCase();
|
|
1465
|
-
const loc = normalizePath(location.pathname).toLowerCase();
|
|
1456
|
+
const loc = decodeURI(normalizePath(location.pathname).toLowerCase());
|
|
1466
1457
|
return [props.end ? path === loc : loc.startsWith(path + "/") || loc === path, path === loc];
|
|
1467
1458
|
});
|
|
1468
1459
|
return (() => {
|
|
1469
|
-
|
|
1460
|
+
var _el$ = _tmpl$();
|
|
1470
1461
|
spread(_el$, mergeProps$1(rest, {
|
|
1471
1462
|
get href() {
|
|
1472
1463
|
return href() || props.href;
|
|
@@ -1620,7 +1611,7 @@ function redirect(url, init = 302) {
|
|
|
1620
1611
|
}
|
|
1621
1612
|
const headers = new Headers(responseInit.headers);
|
|
1622
1613
|
headers.set("Location", url);
|
|
1623
|
-
revalidate && headers.set("X-Revalidate", revalidate.toString());
|
|
1614
|
+
revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
|
|
1624
1615
|
const response = new Response(null, {
|
|
1625
1616
|
...responseInit,
|
|
1626
1617
|
headers: headers
|
|
@@ -1633,7 +1624,7 @@ function reload(init = {}) {
|
|
|
1633
1624
|
...responseInit
|
|
1634
1625
|
} = init;
|
|
1635
1626
|
const headers = new Headers(responseInit.headers);
|
|
1636
|
-
revalidate && headers.set("X-Revalidate", revalidate.toString());
|
|
1627
|
+
revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
|
|
1637
1628
|
return new Response(null, {
|
|
1638
1629
|
...responseInit,
|
|
1639
1630
|
headers
|
|
@@ -1645,7 +1636,7 @@ function json(data, init = {}) {
|
|
|
1645
1636
|
...responseInit
|
|
1646
1637
|
} = init;
|
|
1647
1638
|
const headers = new Headers(responseInit.headers);
|
|
1648
|
-
revalidate && headers.set("X-Revalidate", revalidate.toString());
|
|
1639
|
+
revalidate !== undefined && headers.set("X-Revalidate", revalidate.toString());
|
|
1649
1640
|
headers.set("Content-Type", "application/json");
|
|
1650
1641
|
const response = new Response(JSON.stringify(data), {
|
|
1651
1642
|
...responseInit,
|
package/dist/routing.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export declare const useHref: (to: () => string | undefined) => Accessor<string
|
|
|
9
9
|
export declare const useNavigate: () => Navigator;
|
|
10
10
|
export declare const useLocation: <S = unknown>() => Location<S>;
|
|
11
11
|
export declare const useIsRouting: () => () => boolean;
|
|
12
|
-
export declare const usePreloadRoute: () => (url: URL, options
|
|
13
|
-
preloadData?: boolean
|
|
12
|
+
export declare const usePreloadRoute: () => (url: string | URL, options?: {
|
|
13
|
+
preloadData?: boolean;
|
|
14
14
|
}) => void;
|
|
15
15
|
export declare const useMatch: <S extends string>(path: () => S, matchFilters?: MatchFilters<S> | undefined) => Accessor<import("./types.js").PathMatch | undefined>;
|
|
16
16
|
export declare const useCurrentMatches: () => () => RouteMatch[];
|
|
@@ -21,7 +21,6 @@ export declare function createRoutes(routeDef: RouteDefinition, base?: string):
|
|
|
21
21
|
export declare function createBranch(routes: RouteDescription[], index?: number): Branch;
|
|
22
22
|
export declare function createBranches(routeDef: RouteDefinition | RouteDefinition[], base?: string, stack?: RouteDescription[], branches?: Branch[]): Branch[];
|
|
23
23
|
export declare function getRouteMatches(branches: Branch[], location: string): RouteMatch[];
|
|
24
|
-
export declare function createLocation(path: Accessor<string>, state: Accessor<any>): Location;
|
|
25
24
|
export declare function getIntent(): Intent | undefined;
|
|
26
25
|
export declare function getInPreloadFn(): boolean;
|
|
27
26
|
export declare function setInPreloadFn(value: boolean): void;
|
package/dist/routing.js
CHANGED
|
@@ -23,7 +23,10 @@ export const useHref = (to) => {
|
|
|
23
23
|
export const useNavigate = () => useRouter().navigatorFactory();
|
|
24
24
|
export const useLocation = () => useRouter().location;
|
|
25
25
|
export const useIsRouting = () => useRouter().isRouting;
|
|
26
|
-
export const usePreloadRoute = () =>
|
|
26
|
+
export const usePreloadRoute = () => {
|
|
27
|
+
const pre = useRouter().preloadRoute;
|
|
28
|
+
return (url, options = {}) => pre(url instanceof URL ? url : new URL(url, mockBase), options.preloadData);
|
|
29
|
+
};
|
|
27
30
|
export const useMatch = (path, matchFilters) => {
|
|
28
31
|
const location = useLocation();
|
|
29
32
|
const matchers = createMemo(() => expandOptionals(path()).map(path => createMatcher(path, undefined, matchFilters)));
|
|
@@ -145,7 +148,7 @@ export function getRouteMatches(branches, location) {
|
|
|
145
148
|
}
|
|
146
149
|
return [];
|
|
147
150
|
}
|
|
148
|
-
|
|
151
|
+
function createLocation(path, state, queryWrapper) {
|
|
149
152
|
const origin = new URL(mockBase);
|
|
150
153
|
const url = createMemo(prev => {
|
|
151
154
|
const path_ = path();
|
|
@@ -163,6 +166,7 @@ export function createLocation(path, state) {
|
|
|
163
166
|
const search = createMemo(() => url().search, true);
|
|
164
167
|
const hash = createMemo(() => url().hash);
|
|
165
168
|
const key = () => "";
|
|
169
|
+
const queryFn = on(search, () => extractSearchParams(url()));
|
|
166
170
|
return {
|
|
167
171
|
get pathname() {
|
|
168
172
|
return pathname();
|
|
@@ -179,7 +183,7 @@ export function createLocation(path, state) {
|
|
|
179
183
|
get key() {
|
|
180
184
|
return key();
|
|
181
185
|
},
|
|
182
|
-
query:
|
|
186
|
+
query: queryWrapper ? queryWrapper(queryFn) : createMemoObject(queryFn)
|
|
183
187
|
};
|
|
184
188
|
}
|
|
185
189
|
let intent;
|
|
@@ -239,7 +243,7 @@ export function createRouterContext(integration, branches, getContext, options =
|
|
|
239
243
|
};
|
|
240
244
|
const [reference, setReference] = createSignal(source().value);
|
|
241
245
|
const [state, setState] = createSignal(source().state);
|
|
242
|
-
const location = createLocation(reference, state);
|
|
246
|
+
const location = createLocation(reference, state, utils.queryWrapper);
|
|
243
247
|
const referrers = [];
|
|
244
248
|
const submissions = createSignal(isServer ? initFromFlash() : []);
|
|
245
249
|
const matches = createMemo(() => {
|
|
@@ -248,14 +252,17 @@ export function createRouterContext(integration, branches, getContext, options =
|
|
|
248
252
|
}
|
|
249
253
|
return getRouteMatches(branches(), location.pathname);
|
|
250
254
|
});
|
|
251
|
-
const
|
|
255
|
+
const buildParams = () => {
|
|
252
256
|
const m = matches();
|
|
253
257
|
const params = {};
|
|
254
258
|
for (let i = 0; i < m.length; i++) {
|
|
255
259
|
Object.assign(params, m[i].params);
|
|
256
260
|
}
|
|
257
261
|
return params;
|
|
258
|
-
}
|
|
262
|
+
};
|
|
263
|
+
const params = utils.paramsWrapper
|
|
264
|
+
? utils.paramsWrapper(buildParams, branches)
|
|
265
|
+
: createMemoObject(buildParams);
|
|
259
266
|
const baseRoute = {
|
|
260
267
|
pattern: basePath,
|
|
261
268
|
path: () => basePath,
|
|
@@ -302,7 +309,6 @@ export function createRouterContext(integration, branches, getContext, options =
|
|
|
302
309
|
scroll: true,
|
|
303
310
|
...options
|
|
304
311
|
};
|
|
305
|
-
let s;
|
|
306
312
|
const resolvedTo = resolve
|
|
307
313
|
? route.resolvePath(to)
|
|
308
314
|
: resolvePath((queryOnly && location.pathname) || "", to);
|
|
@@ -345,7 +351,7 @@ export function createRouterContext(integration, branches, getContext, options =
|
|
|
345
351
|
referrers.length = 0;
|
|
346
352
|
}
|
|
347
353
|
}
|
|
348
|
-
function preloadRoute(url,
|
|
354
|
+
function preloadRoute(url, preloadData) {
|
|
349
355
|
const matches = getRouteMatches(branches(), url.pathname);
|
|
350
356
|
const prevIntent = intent;
|
|
351
357
|
intent = "preload";
|
|
@@ -356,7 +362,7 @@ export function createRouterContext(integration, branches, getContext, options =
|
|
|
356
362
|
route.component.preload();
|
|
357
363
|
const { preload } = route;
|
|
358
364
|
inPreloadFn = true;
|
|
359
|
-
|
|
365
|
+
preloadData &&
|
|
360
366
|
preload &&
|
|
361
367
|
runWithOwner(getContext(), () => preload({
|
|
362
368
|
params,
|
package/dist/types.d.ts
CHANGED
|
@@ -126,6 +126,8 @@ export interface RouterUtils {
|
|
|
126
126
|
parsePath(str: string): string;
|
|
127
127
|
go(delta: number): void;
|
|
128
128
|
beforeLeave: BeforeLeaveLifecycle;
|
|
129
|
+
paramsWrapper: (getParams: () => Params, branches: () => Branch[]) => Params;
|
|
130
|
+
queryWrapper: (getQuery: () => Params) => Params;
|
|
129
131
|
}
|
|
130
132
|
export interface RouterContext {
|
|
131
133
|
base: RouteContext;
|
|
@@ -137,9 +139,7 @@ export interface RouterContext {
|
|
|
137
139
|
renderPath(path: string): string;
|
|
138
140
|
parsePath(str: string): string;
|
|
139
141
|
beforeLeave: BeforeLeaveLifecycle;
|
|
140
|
-
preloadRoute: (url: URL,
|
|
141
|
-
preloadData?: boolean;
|
|
142
|
-
}) => void;
|
|
142
|
+
preloadRoute: (url: URL, preloadData?: boolean) => void;
|
|
143
143
|
singleFlight: boolean;
|
|
144
144
|
submissions: Signal<Submission<any, any>[]>;
|
|
145
145
|
}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"Ryan Turnquist"
|
|
7
7
|
],
|
|
8
8
|
"license": "MIT",
|
|
9
|
-
"version": "0.14.
|
|
9
|
+
"version": "0.14.9",
|
|
10
10
|
"homepage": "https://github.com/solidjs/solid-router#readme",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
"@rollup/plugin-terser": "0.4.4",
|
|
38
38
|
"@types/jest": "^29.5.11",
|
|
39
39
|
"@types/node": "^20.11.14",
|
|
40
|
-
"babel-preset-solid": "^1.
|
|
40
|
+
"babel-preset-solid": "^1.9.2",
|
|
41
41
|
"jsdom": "^24.0.0",
|
|
42
42
|
"prettier": "^2.7.0",
|
|
43
43
|
"rollup": "^4.9.6",
|
|
44
|
-
"solid-js": "^1.
|
|
44
|
+
"solid-js": "^1.9.2",
|
|
45
45
|
"typescript": "^5.3.3",
|
|
46
|
-
"vite": "^5.
|
|
46
|
+
"vite": "^5.4.8",
|
|
47
47
|
"vite-plugin-solid": "^2.9.1",
|
|
48
|
-
"vitest": "^1.2
|
|
48
|
+
"vitest": "^2.1.2"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"solid-js": "^1.8.6"
|