@tanstack/router-core 1.131.5 → 1.132.0-alpha.0
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/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +9 -7
- package/dist/cjs/defer.cjs +1 -1
- package/dist/cjs/defer.cjs.map +1 -1
- package/dist/cjs/index.cjs +0 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/lru-cache.cjs.map +1 -1
- package/dist/cjs/not-found.cjs +1 -1
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/path.cjs +10 -12
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/qss.cjs.map +1 -1
- package/dist/cjs/redirect.cjs.map +1 -1
- package/dist/cjs/route.cjs +6 -7
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/router.cjs +167 -194
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +1 -2
- package/dist/cjs/scroll-restoration.cjs +2 -3
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.d.cts +9 -0
- package/dist/cjs/searchMiddleware.cjs.map +1 -1
- package/dist/cjs/searchParams.cjs.map +1 -1
- package/dist/cjs/ssr/createRequestHandler.cjs +2 -3
- package/dist/cjs/ssr/createRequestHandler.cjs.map +1 -1
- package/dist/cjs/ssr/handlerCallback.cjs.map +1 -1
- package/dist/cjs/ssr/headers.cjs.map +1 -1
- package/dist/cjs/ssr/json.cjs +1 -1
- package/dist/cjs/ssr/json.cjs.map +1 -1
- package/dist/cjs/ssr/seroval-plugins.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-client.cjs +47 -48
- package/dist/cjs/ssr/ssr-client.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-server.cjs +2 -3
- package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
- package/dist/cjs/ssr/transformStreamWithRouter.cjs +3 -4
- package/dist/cjs/ssr/transformStreamWithRouter.cjs.map +1 -1
- package/dist/cjs/typePrimitives.d.cts +6 -6
- package/dist/cjs/utils.cjs +4 -27
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +0 -6
- package/dist/esm/Matches.d.ts +9 -7
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/defer.js +1 -1
- package/dist/esm/defer.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -3
- package/dist/esm/lru-cache.js.map +1 -1
- package/dist/esm/not-found.js +1 -1
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/path.js +10 -12
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/qss.js.map +1 -1
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/route.js +6 -7
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +1 -2
- package/dist/esm/router.js +167 -194
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration.d.ts +9 -0
- package/dist/esm/scroll-restoration.js +2 -3
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/searchMiddleware.js.map +1 -1
- package/dist/esm/searchParams.js.map +1 -1
- package/dist/esm/ssr/createRequestHandler.js +2 -3
- package/dist/esm/ssr/createRequestHandler.js.map +1 -1
- package/dist/esm/ssr/handlerCallback.js.map +1 -1
- package/dist/esm/ssr/headers.js.map +1 -1
- package/dist/esm/ssr/json.js +1 -1
- package/dist/esm/ssr/json.js.map +1 -1
- package/dist/esm/ssr/seroval-plugins.js.map +1 -1
- package/dist/esm/ssr/ssr-client.js +47 -48
- package/dist/esm/ssr/ssr-client.js.map +1 -1
- package/dist/esm/ssr/ssr-server.js +2 -3
- package/dist/esm/ssr/ssr-server.js.map +1 -1
- package/dist/esm/ssr/transformStreamWithRouter.js +3 -4
- package/dist/esm/ssr/transformStreamWithRouter.js.map +1 -1
- package/dist/esm/typePrimitives.d.ts +6 -6
- package/dist/esm/utils.d.ts +0 -6
- package/dist/esm/utils.js +5 -28
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/Matches.ts +8 -16
- package/src/index.ts +0 -2
- package/src/router.ts +111 -107
- package/src/ssr/ssr-client.ts +41 -42
- package/src/typePrimitives.ts +6 -6
- package/src/utils.ts +0 -41
package/dist/esm/router.js
CHANGED
|
@@ -27,9 +27,9 @@ function defaultSerializeError(err) {
|
|
|
27
27
|
function getLocationChangeInfo(routerState) {
|
|
28
28
|
const fromLocation = routerState.resolvedLocation;
|
|
29
29
|
const toLocation = routerState.location;
|
|
30
|
-
const pathChanged =
|
|
31
|
-
const hrefChanged =
|
|
32
|
-
const hashChanged =
|
|
30
|
+
const pathChanged = fromLocation?.pathname !== toLocation.pathname;
|
|
31
|
+
const hrefChanged = fromLocation?.href !== toLocation.href;
|
|
32
|
+
const hashChanged = fromLocation?.hash !== toLocation.hash;
|
|
33
33
|
return { fromLocation, toLocation, pathChanged, hrefChanged, hashChanged };
|
|
34
34
|
}
|
|
35
35
|
class RouterCore {
|
|
@@ -48,7 +48,6 @@ class RouterCore {
|
|
|
48
48
|
this.isScrollRestorationSetup = false;
|
|
49
49
|
this.startTransition = (fn) => fn();
|
|
50
50
|
this.update = (newOptions) => {
|
|
51
|
-
var _a;
|
|
52
51
|
if (newOptions.notFoundRoute) {
|
|
53
52
|
console.warn(
|
|
54
53
|
"The notFoundRoute API is deprecated and will be removed in the next major version. See https://tanstack.com/router/v1/docs/framework/react/guide/not-found-errors#migrating-from-notfoundroute for more info."
|
|
@@ -77,7 +76,7 @@ class RouterCore {
|
|
|
77
76
|
this.history = this.options.history ?? (this.isServer ? createMemoryHistory({
|
|
78
77
|
initialEntries: [this.basepath || "/"]
|
|
79
78
|
}) : createBrowserHistory());
|
|
80
|
-
this.
|
|
79
|
+
this.latestLocation = this.parseLocation();
|
|
81
80
|
}
|
|
82
81
|
if (this.options.routeTree !== this.routeTree) {
|
|
83
82
|
this.routeTree = this.options.routeTree;
|
|
@@ -96,18 +95,12 @@ class RouterCore {
|
|
|
96
95
|
});
|
|
97
96
|
setupScrollRestoration(this);
|
|
98
97
|
}
|
|
99
|
-
if (typeof window !== "undefined" && "CSS" in window && typeof
|
|
98
|
+
if (typeof window !== "undefined" && "CSS" in window && typeof window.CSS?.supports === "function") {
|
|
100
99
|
this.isViewTransitionTypesSupported = window.CSS.supports(
|
|
101
100
|
"selector(:active-view-transition-type(a)"
|
|
102
101
|
);
|
|
103
102
|
}
|
|
104
103
|
};
|
|
105
|
-
this.updateLatestLocation = () => {
|
|
106
|
-
this.latestLocation = this.parseLocation(
|
|
107
|
-
this.history.location,
|
|
108
|
-
this.latestLocation
|
|
109
|
-
);
|
|
110
|
-
};
|
|
111
104
|
this.buildRouteTree = () => {
|
|
112
105
|
const { routesById, routesByPath, flatRoutes } = processRouteTree({
|
|
113
106
|
routeTree: this.routeTree,
|
|
@@ -145,7 +138,7 @@ class RouterCore {
|
|
|
145
138
|
}
|
|
146
139
|
});
|
|
147
140
|
};
|
|
148
|
-
this.parseLocation = (
|
|
141
|
+
this.parseLocation = (previousLocation, locationToParse) => {
|
|
149
142
|
const parse = ({
|
|
150
143
|
pathname,
|
|
151
144
|
search,
|
|
@@ -157,13 +150,13 @@ class RouterCore {
|
|
|
157
150
|
return {
|
|
158
151
|
pathname,
|
|
159
152
|
searchStr,
|
|
160
|
-
search: replaceEqualDeep(previousLocation
|
|
153
|
+
search: replaceEqualDeep(previousLocation?.search, parsedSearch),
|
|
161
154
|
hash: hash.split("#").reverse()[0] ?? "",
|
|
162
155
|
href: `${pathname}${searchStr}${hash}`,
|
|
163
|
-
state: replaceEqualDeep(previousLocation
|
|
156
|
+
state: replaceEqualDeep(previousLocation?.state, state)
|
|
164
157
|
};
|
|
165
158
|
};
|
|
166
|
-
const location = parse(locationToParse);
|
|
159
|
+
const location = parse(locationToParse ?? this.history.location);
|
|
167
160
|
const { __tempLocation, __tempKey } = location.state;
|
|
168
161
|
if (__tempLocation && (!__tempKey || __tempKey === this.tempLocationKey)) {
|
|
169
162
|
const parsedTempLocation = parse(__tempLocation);
|
|
@@ -217,18 +210,21 @@ class RouterCore {
|
|
|
217
210
|
const match = this.getMatch(id);
|
|
218
211
|
if (!match) return;
|
|
219
212
|
match.abortController.abort();
|
|
220
|
-
|
|
221
|
-
|
|
213
|
+
this.updateMatch(id, (prev) => {
|
|
214
|
+
clearTimeout(prev.pendingTimeout);
|
|
215
|
+
return {
|
|
216
|
+
...prev,
|
|
217
|
+
pendingTimeout: void 0
|
|
218
|
+
};
|
|
219
|
+
});
|
|
222
220
|
};
|
|
223
221
|
this.cancelMatches = () => {
|
|
224
|
-
|
|
225
|
-
(_a = this.state.pendingMatches) == null ? void 0 : _a.forEach((match) => {
|
|
222
|
+
this.state.pendingMatches?.forEach((match) => {
|
|
226
223
|
this.cancelMatch(match.id);
|
|
227
224
|
});
|
|
228
225
|
};
|
|
229
226
|
this.buildLocation = (opts) => {
|
|
230
227
|
const build = (dest = {}) => {
|
|
231
|
-
var _a;
|
|
232
228
|
const currentLocation = dest._fromLocation || this.latestLocation;
|
|
233
229
|
const allCurrentLocationMatches = this.matchRoutes(currentLocation, {
|
|
234
230
|
_buildLocation: true
|
|
@@ -269,13 +265,16 @@ class RouterCore {
|
|
|
269
265
|
params: nextParams ?? {},
|
|
270
266
|
parseCache: this.parsePathnameCache
|
|
271
267
|
}).interpolatedPath;
|
|
272
|
-
const destRoutes = this.matchRoutes(
|
|
273
|
-
|
|
274
|
-
|
|
268
|
+
const destRoutes = this.matchRoutes(
|
|
269
|
+
interpolatedNextTo,
|
|
270
|
+
{},
|
|
271
|
+
{
|
|
272
|
+
_buildLocation: true
|
|
273
|
+
}
|
|
274
|
+
).map((d) => this.looseRoutesById[d.routeId]);
|
|
275
275
|
if (Object.keys(nextParams).length > 0) {
|
|
276
276
|
destRoutes.map((route) => {
|
|
277
|
-
|
|
278
|
-
return ((_a2 = route.options.params) == null ? void 0 : _a2.stringify) ?? route.options.stringifyParams;
|
|
277
|
+
return route.options.params?.stringify ?? route.options.stringifyParams;
|
|
279
278
|
}).filter(Boolean).forEach((fn) => {
|
|
280
279
|
nextParams = { ...nextParams, ...fn(nextParams) };
|
|
281
280
|
});
|
|
@@ -291,7 +290,7 @@ class RouterCore {
|
|
|
291
290
|
parseCache: this.parsePathnameCache
|
|
292
291
|
}).interpolatedPath;
|
|
293
292
|
let nextSearch = fromSearch;
|
|
294
|
-
if (opts._includeValidateSearch &&
|
|
293
|
+
if (opts._includeValidateSearch && this.options.search?.strict) {
|
|
295
294
|
let validatedSearch = {};
|
|
296
295
|
destRoutes.forEach((route) => {
|
|
297
296
|
try {
|
|
@@ -332,12 +331,11 @@ class RouterCore {
|
|
|
332
331
|
};
|
|
333
332
|
};
|
|
334
333
|
const buildWithMatches = (dest = {}, maskedDest) => {
|
|
335
|
-
var _a;
|
|
336
334
|
const next = build(dest);
|
|
337
335
|
let maskedNext = maskedDest ? build(maskedDest) : void 0;
|
|
338
336
|
if (!maskedNext) {
|
|
339
337
|
let params = {};
|
|
340
|
-
const foundMask =
|
|
338
|
+
const foundMask = this.options.routeMasks?.find((d) => {
|
|
341
339
|
const match = matchPathname(
|
|
342
340
|
this.basepath,
|
|
343
341
|
next.pathname,
|
|
@@ -403,7 +401,7 @@ class RouterCore {
|
|
|
403
401
|
const isSameUrl = this.latestLocation.href === next.href;
|
|
404
402
|
const previousCommitPromise = this.commitLocationPromise;
|
|
405
403
|
this.commitLocationPromise = createControlledPromise(() => {
|
|
406
|
-
previousCommitPromise
|
|
404
|
+
previousCommitPromise?.resolve();
|
|
407
405
|
});
|
|
408
406
|
if (isSameUrl && isSameState()) {
|
|
409
407
|
this.load();
|
|
@@ -507,7 +505,7 @@ class RouterCore {
|
|
|
507
505
|
};
|
|
508
506
|
this.beforeLoad = () => {
|
|
509
507
|
this.cancelMatches();
|
|
510
|
-
this.
|
|
508
|
+
this.latestLocation = this.parseLocation(this.latestLocation);
|
|
511
509
|
if (this.isServer) {
|
|
512
510
|
const nextLocation = this.buildLocation({
|
|
513
511
|
to: this.latestLocation.pathname,
|
|
@@ -548,7 +546,6 @@ class RouterCore {
|
|
|
548
546
|
let loadPromise;
|
|
549
547
|
loadPromise = new Promise((resolve) => {
|
|
550
548
|
this.startTransition(async () => {
|
|
551
|
-
var _a;
|
|
552
549
|
try {
|
|
553
550
|
this.beforeLoad();
|
|
554
551
|
const next = this.latestLocation;
|
|
@@ -570,7 +567,7 @@ class RouterCore {
|
|
|
570
567
|
})
|
|
571
568
|
});
|
|
572
569
|
await this.loadMatches({
|
|
573
|
-
sync: opts
|
|
570
|
+
sync: opts?.sync,
|
|
574
571
|
matches: this.state.pendingMatches,
|
|
575
572
|
location: next,
|
|
576
573
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
@@ -612,8 +609,7 @@ class RouterCore {
|
|
|
612
609
|
[stayingMatches, "onStay"]
|
|
613
610
|
].forEach(([matches, hook]) => {
|
|
614
611
|
matches.forEach((match) => {
|
|
615
|
-
|
|
616
|
-
(_b = (_a2 = this.looseRoutesById[match.routeId].options)[hook]) == null ? void 0 : _b.call(_a2, match);
|
|
612
|
+
this.looseRoutesById[match.routeId].options[hook]?.(match);
|
|
617
613
|
});
|
|
618
614
|
});
|
|
619
615
|
});
|
|
@@ -639,7 +635,7 @@ class RouterCore {
|
|
|
639
635
|
}));
|
|
640
636
|
}
|
|
641
637
|
if (this.latestLoadPromise === loadPromise) {
|
|
642
|
-
|
|
638
|
+
this.commitLocationPromise?.resolve();
|
|
643
639
|
this.latestLoadPromise = void 0;
|
|
644
640
|
this.commitLocationPromise = void 0;
|
|
645
641
|
}
|
|
@@ -685,22 +681,17 @@ class RouterCore {
|
|
|
685
681
|
}
|
|
686
682
|
};
|
|
687
683
|
this.updateMatch = (id, updater) => {
|
|
688
|
-
|
|
689
|
-
const matchesKey = ((_a = this.state.pendingMatches) == null ? void 0 : _a.some((d) => d.id === id)) ? "pendingMatches" : this.state.matches.some((d) => d.id === id) ? "matches" : this.state.cachedMatches.some((d) => d.id === id) ? "cachedMatches" : "";
|
|
684
|
+
const matchesKey = this.state.pendingMatches?.some((d) => d.id === id) ? "pendingMatches" : this.state.matches.some((d) => d.id === id) ? "matches" : this.state.cachedMatches.some((d) => d.id === id) ? "cachedMatches" : "";
|
|
690
685
|
if (matchesKey) {
|
|
691
|
-
this.__store.setState((s) => {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
[matchesKey]: (_a2 = s[matchesKey]) == null ? void 0 : _a2.map((d) => d.id === id ? updater(d) : d)
|
|
696
|
-
};
|
|
697
|
-
});
|
|
686
|
+
this.__store.setState((s) => ({
|
|
687
|
+
...s,
|
|
688
|
+
[matchesKey]: s[matchesKey]?.map((d) => d.id === id ? updater(d) : d)
|
|
689
|
+
}));
|
|
698
690
|
}
|
|
699
691
|
};
|
|
700
692
|
this.getMatch = (matchId) => {
|
|
701
|
-
var _a;
|
|
702
693
|
const findFn = (d) => d.id === matchId;
|
|
703
|
-
return this.state.cachedMatches.find(findFn) ??
|
|
694
|
+
return this.state.cachedMatches.find(findFn) ?? this.state.pendingMatches?.find(findFn) ?? this.state.matches.find(findFn);
|
|
704
695
|
};
|
|
705
696
|
this.loadMatches = async ({
|
|
706
697
|
location,
|
|
@@ -715,7 +706,7 @@ class RouterCore {
|
|
|
715
706
|
const triggerOnReady = async () => {
|
|
716
707
|
if (!rendered) {
|
|
717
708
|
rendered = true;
|
|
718
|
-
await
|
|
709
|
+
await onReady?.();
|
|
719
710
|
}
|
|
720
711
|
};
|
|
721
712
|
const resolvePreload = (matchId) => {
|
|
@@ -725,7 +716,6 @@ class RouterCore {
|
|
|
725
716
|
triggerOnReady();
|
|
726
717
|
}
|
|
727
718
|
const handleRedirectAndNotFound = (match, err) => {
|
|
728
|
-
var _a, _b, _c;
|
|
729
719
|
if (isRedirect(err) || isNotFound(err)) {
|
|
730
720
|
if (isRedirect(err)) {
|
|
731
721
|
if (err.redirectHandled) {
|
|
@@ -734,20 +724,20 @@ class RouterCore {
|
|
|
734
724
|
}
|
|
735
725
|
}
|
|
736
726
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
match._nonReactive.beforeLoadPromise = void 0;
|
|
740
|
-
match._nonReactive.loaderPromise = void 0;
|
|
727
|
+
match.beforeLoadPromise?.resolve();
|
|
728
|
+
match.loaderPromise?.resolve();
|
|
741
729
|
updateMatch(match.id, (prev) => ({
|
|
742
730
|
...prev,
|
|
743
731
|
status: isRedirect(err) ? "redirected" : isNotFound(err) ? "notFound" : "error",
|
|
744
732
|
isFetching: false,
|
|
745
|
-
error: err
|
|
733
|
+
error: err,
|
|
734
|
+
beforeLoadPromise: void 0,
|
|
735
|
+
loaderPromise: void 0
|
|
746
736
|
}));
|
|
747
737
|
if (!err.routeId) {
|
|
748
738
|
err.routeId = match.routeId;
|
|
749
739
|
}
|
|
750
|
-
|
|
740
|
+
match.loadPromise?.resolve();
|
|
751
741
|
if (isRedirect(err)) {
|
|
752
742
|
rendered = true;
|
|
753
743
|
err.options._fromLocation = location;
|
|
@@ -764,7 +754,7 @@ class RouterCore {
|
|
|
764
754
|
};
|
|
765
755
|
const shouldSkipLoader = (matchId) => {
|
|
766
756
|
const match = this.getMatch(matchId);
|
|
767
|
-
if (!this.isServer && match.
|
|
757
|
+
if (!this.isServer && match._dehydrated) {
|
|
768
758
|
return true;
|
|
769
759
|
}
|
|
770
760
|
if (this.isServer) {
|
|
@@ -778,10 +768,8 @@ class RouterCore {
|
|
|
778
768
|
await new Promise((resolveAll, rejectAll) => {
|
|
779
769
|
;
|
|
780
770
|
(async () => {
|
|
781
|
-
var _a, _b, _c, _d;
|
|
782
771
|
try {
|
|
783
772
|
const handleSerialError = (index, err, routerCode) => {
|
|
784
|
-
var _a2, _b2;
|
|
785
773
|
const { id: matchId, routeId } = matches[index];
|
|
786
774
|
const route = this.looseRoutesById[routeId];
|
|
787
775
|
if (err instanceof Promise) {
|
|
@@ -791,29 +779,28 @@ class RouterCore {
|
|
|
791
779
|
firstBadMatchIndex = firstBadMatchIndex ?? index;
|
|
792
780
|
handleRedirectAndNotFound(this.getMatch(matchId), err);
|
|
793
781
|
try {
|
|
794
|
-
|
|
782
|
+
route.options.onError?.(err);
|
|
795
783
|
} catch (errorHandlerErr) {
|
|
796
784
|
err = errorHandlerErr;
|
|
797
785
|
handleRedirectAndNotFound(this.getMatch(matchId), err);
|
|
798
786
|
}
|
|
799
787
|
updateMatch(matchId, (prev) => {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
prev._nonReactive.beforeLoadPromise = void 0;
|
|
803
|
-
(_b3 = prev._nonReactive.loadPromise) == null ? void 0 : _b3.resolve();
|
|
788
|
+
prev.beforeLoadPromise?.resolve();
|
|
789
|
+
prev.loadPromise?.resolve();
|
|
804
790
|
return {
|
|
805
791
|
...prev,
|
|
806
792
|
error: err,
|
|
807
793
|
status: "error",
|
|
808
794
|
isFetching: false,
|
|
809
795
|
updatedAt: Date.now(),
|
|
810
|
-
abortController: new AbortController()
|
|
796
|
+
abortController: new AbortController(),
|
|
797
|
+
beforeLoadPromise: void 0
|
|
811
798
|
};
|
|
812
799
|
});
|
|
813
800
|
};
|
|
814
801
|
for (const [index, { id: matchId, routeId }] of matches.entries()) {
|
|
815
802
|
const existingMatch = this.getMatch(matchId);
|
|
816
|
-
const parentMatchId =
|
|
803
|
+
const parentMatchId = matches[index - 1]?.id;
|
|
817
804
|
const parentMatch = parentMatchId ? this.getMatch(parentMatchId) : void 0;
|
|
818
805
|
const route = this.looseRoutesById[routeId];
|
|
819
806
|
const pendingMs = route.options.pendingMs ?? this.options.defaultPendingMs;
|
|
@@ -823,7 +810,7 @@ class RouterCore {
|
|
|
823
810
|
ssr = matchId === rootRouteId;
|
|
824
811
|
} else {
|
|
825
812
|
const defaultSsr = this.options.defaultSsr ?? true;
|
|
826
|
-
if (
|
|
813
|
+
if (parentMatch?.ssr === false) {
|
|
827
814
|
ssr = false;
|
|
828
815
|
} else {
|
|
829
816
|
let tempSsr;
|
|
@@ -857,39 +844,44 @@ class RouterCore {
|
|
|
857
844
|
} else {
|
|
858
845
|
tempSsr = route.options.ssr;
|
|
859
846
|
}
|
|
860
|
-
if (tempSsr === true &&
|
|
847
|
+
if (tempSsr === true && parentMatch?.ssr === "data-only") {
|
|
861
848
|
ssr = "data-only";
|
|
862
849
|
} else {
|
|
863
850
|
ssr = tempSsr;
|
|
864
851
|
}
|
|
865
852
|
}
|
|
866
853
|
}
|
|
867
|
-
|
|
854
|
+
updateMatch(matchId, (prev) => ({
|
|
855
|
+
...prev,
|
|
856
|
+
ssr
|
|
857
|
+
}));
|
|
868
858
|
}
|
|
869
859
|
if (shouldSkipLoader(matchId)) {
|
|
870
860
|
continue;
|
|
871
861
|
}
|
|
872
|
-
const shouldPending = !!(onReady && !this.isServer && !resolvePreload(matchId) && (route.options.loader || route.options.beforeLoad || routeNeedsPreload(route)) && typeof pendingMs === "number" && pendingMs !== Infinity && (route.options.pendingComponent ??
|
|
862
|
+
const shouldPending = !!(onReady && !this.isServer && !resolvePreload(matchId) && (route.options.loader || route.options.beforeLoad || routeNeedsPreload(route)) && typeof pendingMs === "number" && pendingMs !== Infinity && (route.options.pendingComponent ?? this.options?.defaultPendingComponent));
|
|
873
863
|
let executeBeforeLoad = true;
|
|
874
864
|
const setupPendingTimeout = () => {
|
|
875
|
-
|
|
876
|
-
if (shouldPending && match._nonReactive.pendingTimeout === void 0) {
|
|
865
|
+
if (shouldPending && this.getMatch(matchId).pendingTimeout === void 0) {
|
|
877
866
|
const pendingTimeout = setTimeout(() => {
|
|
878
867
|
try {
|
|
879
868
|
triggerOnReady();
|
|
880
869
|
} catch {
|
|
881
870
|
}
|
|
882
871
|
}, pendingMs);
|
|
883
|
-
|
|
872
|
+
updateMatch(matchId, (prev) => ({
|
|
873
|
+
...prev,
|
|
874
|
+
pendingTimeout
|
|
875
|
+
}));
|
|
884
876
|
}
|
|
885
877
|
};
|
|
886
878
|
if (
|
|
887
879
|
// If we are in the middle of a load, either of these will be present
|
|
888
880
|
// (not to be confused with `loadPromise`, which is always defined)
|
|
889
|
-
existingMatch.
|
|
881
|
+
existingMatch.beforeLoadPromise || existingMatch.loaderPromise
|
|
890
882
|
) {
|
|
891
883
|
setupPendingTimeout();
|
|
892
|
-
await existingMatch.
|
|
884
|
+
await existingMatch.beforeLoadPromise;
|
|
893
885
|
const match = this.getMatch(matchId);
|
|
894
886
|
if (match.status === "error") {
|
|
895
887
|
executeBeforeLoad = true;
|
|
@@ -899,11 +891,15 @@ class RouterCore {
|
|
|
899
891
|
}
|
|
900
892
|
if (executeBeforeLoad) {
|
|
901
893
|
try {
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
894
|
+
updateMatch(matchId, (prev) => {
|
|
895
|
+
const prevLoadPromise = prev.loadPromise;
|
|
896
|
+
return {
|
|
897
|
+
...prev,
|
|
898
|
+
loadPromise: createControlledPromise(() => {
|
|
899
|
+
prevLoadPromise?.resolve();
|
|
900
|
+
}),
|
|
901
|
+
beforeLoadPromise: createControlledPromise()
|
|
902
|
+
};
|
|
907
903
|
});
|
|
908
904
|
const { paramsError, searchError } = this.getMatch(matchId);
|
|
909
905
|
if (paramsError) {
|
|
@@ -914,7 +910,7 @@ class RouterCore {
|
|
|
914
910
|
}
|
|
915
911
|
setupPendingTimeout();
|
|
916
912
|
const abortController = new AbortController();
|
|
917
|
-
const parentMatchContext =
|
|
913
|
+
const parentMatchContext = parentMatch?.context ?? this.options.context ?? {};
|
|
918
914
|
updateMatch(matchId, (prev) => ({
|
|
919
915
|
...prev,
|
|
920
916
|
isFetching: "beforeLoad",
|
|
@@ -939,7 +935,7 @@ class RouterCore {
|
|
|
939
935
|
cause: preload ? "preload" : cause,
|
|
940
936
|
matches
|
|
941
937
|
};
|
|
942
|
-
const beforeLoadContext = await
|
|
938
|
+
const beforeLoadContext = await route.options.beforeLoad?.(beforeLoadFnContext);
|
|
943
939
|
if (isRedirect(beforeLoadContext) || isNotFound(beforeLoadContext)) {
|
|
944
940
|
handleSerialError(index, beforeLoadContext, "BEFORE_LOAD");
|
|
945
941
|
}
|
|
@@ -959,11 +955,10 @@ class RouterCore {
|
|
|
959
955
|
handleSerialError(index, err, "BEFORE_LOAD");
|
|
960
956
|
}
|
|
961
957
|
updateMatch(matchId, (prev) => {
|
|
962
|
-
|
|
963
|
-
(_a2 = prev._nonReactive.beforeLoadPromise) == null ? void 0 : _a2.resolve();
|
|
964
|
-
prev._nonReactive.beforeLoadPromise = void 0;
|
|
958
|
+
prev.beforeLoadPromise?.resolve();
|
|
965
959
|
return {
|
|
966
960
|
...prev,
|
|
961
|
+
beforeLoadPromise: void 0,
|
|
967
962
|
isFetching: false
|
|
968
963
|
};
|
|
969
964
|
});
|
|
@@ -974,12 +969,10 @@ class RouterCore {
|
|
|
974
969
|
validResolvedMatches.forEach(({ id: matchId, routeId }, index) => {
|
|
975
970
|
matchPromises.push(
|
|
976
971
|
(async () => {
|
|
977
|
-
var _a2, _b2;
|
|
978
972
|
let loaderShouldRunAsync = false;
|
|
979
973
|
let loaderIsRunningAsync = false;
|
|
980
974
|
const route = this.looseRoutesById[routeId];
|
|
981
975
|
const executeHead = async () => {
|
|
982
|
-
var _a3, _b3, _c2, _d2, _e, _f;
|
|
983
976
|
const match = this.getMatch(matchId);
|
|
984
977
|
if (!match) {
|
|
985
978
|
return;
|
|
@@ -990,13 +983,13 @@ class RouterCore {
|
|
|
990
983
|
params: match.params,
|
|
991
984
|
loaderData: match.loaderData
|
|
992
985
|
};
|
|
993
|
-
const headFnContent = await
|
|
994
|
-
const meta = headFnContent
|
|
995
|
-
const links = headFnContent
|
|
996
|
-
const headScripts = headFnContent
|
|
997
|
-
const styles = headFnContent
|
|
998
|
-
const scripts = await
|
|
999
|
-
const headers = await
|
|
986
|
+
const headFnContent = await route.options.head?.(assetContext);
|
|
987
|
+
const meta = headFnContent?.meta;
|
|
988
|
+
const links = headFnContent?.links;
|
|
989
|
+
const headScripts = headFnContent?.scripts;
|
|
990
|
+
const styles = headFnContent?.styles;
|
|
991
|
+
const scripts = await route.options.scripts?.(assetContext);
|
|
992
|
+
const headers = await route.options.headers?.(assetContext);
|
|
1000
993
|
return {
|
|
1001
994
|
meta,
|
|
1002
995
|
links,
|
|
@@ -1008,8 +1001,8 @@ class RouterCore {
|
|
|
1008
1001
|
};
|
|
1009
1002
|
const potentialPendingMinPromise = async () => {
|
|
1010
1003
|
const latestMatch = this.getMatch(matchId);
|
|
1011
|
-
if (latestMatch.
|
|
1012
|
-
await latestMatch.
|
|
1004
|
+
if (latestMatch.minPendingPromise) {
|
|
1005
|
+
await latestMatch.minPendingPromise;
|
|
1013
1006
|
}
|
|
1014
1007
|
};
|
|
1015
1008
|
const prevMatch = this.getMatch(matchId);
|
|
@@ -1022,11 +1015,11 @@ class RouterCore {
|
|
|
1022
1015
|
}));
|
|
1023
1016
|
return this.getMatch(matchId);
|
|
1024
1017
|
}
|
|
1025
|
-
} else if (prevMatch.
|
|
1018
|
+
} else if (prevMatch.loaderPromise) {
|
|
1026
1019
|
if (prevMatch.status === "success" && !sync && !prevMatch.preload) {
|
|
1027
1020
|
return this.getMatch(matchId);
|
|
1028
1021
|
}
|
|
1029
|
-
await prevMatch.
|
|
1022
|
+
await prevMatch.loaderPromise;
|
|
1030
1023
|
const match = this.getMatch(matchId);
|
|
1031
1024
|
if (match.error) {
|
|
1032
1025
|
handleRedirectAndNotFound(match, match.error);
|
|
@@ -1060,15 +1053,12 @@ class RouterCore {
|
|
|
1060
1053
|
const staleAge = preload ? route.options.preloadStaleTime ?? this.options.defaultPreloadStaleTime ?? 3e4 : route.options.staleTime ?? this.options.defaultStaleTime ?? 0;
|
|
1061
1054
|
const shouldReloadOption = route.options.shouldReload;
|
|
1062
1055
|
const shouldReload = typeof shouldReloadOption === "function" ? shouldReloadOption(getLoaderContext()) : shouldReloadOption;
|
|
1063
|
-
updateMatch(matchId, (prev) => {
|
|
1064
|
-
prev
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
};
|
|
1069
|
-
});
|
|
1056
|
+
updateMatch(matchId, (prev) => ({
|
|
1057
|
+
...prev,
|
|
1058
|
+
loaderPromise: createControlledPromise(),
|
|
1059
|
+
preload: !!preload && !this.state.matches.some((d) => d.id === matchId)
|
|
1060
|
+
}));
|
|
1070
1061
|
const runLoader = async () => {
|
|
1071
|
-
var _a3, _b3, _c2, _d2;
|
|
1072
1062
|
try {
|
|
1073
1063
|
try {
|
|
1074
1064
|
if (!this.isServer || this.isServer && this.getMatch(matchId).ssr === true) {
|
|
@@ -1078,7 +1068,7 @@ class RouterCore {
|
|
|
1078
1068
|
...prev,
|
|
1079
1069
|
isFetching: "loader"
|
|
1080
1070
|
}));
|
|
1081
|
-
const loaderData = await
|
|
1071
|
+
const loaderData = await route.options.loader?.(getLoaderContext());
|
|
1082
1072
|
handleRedirectAndNotFound(
|
|
1083
1073
|
this.getMatch(matchId),
|
|
1084
1074
|
loaderData
|
|
@@ -1104,7 +1094,7 @@ class RouterCore {
|
|
|
1104
1094
|
await potentialPendingMinPromise();
|
|
1105
1095
|
handleRedirectAndNotFound(this.getMatch(matchId), e);
|
|
1106
1096
|
try {
|
|
1107
|
-
|
|
1097
|
+
route.options.onError?.(e);
|
|
1108
1098
|
} catch (onErrorError) {
|
|
1109
1099
|
error = onErrorError;
|
|
1110
1100
|
handleRedirectAndNotFound(
|
|
@@ -1123,13 +1113,11 @@ class RouterCore {
|
|
|
1123
1113
|
}
|
|
1124
1114
|
} catch (err) {
|
|
1125
1115
|
const head = await executeHead();
|
|
1126
|
-
updateMatch(matchId, (prev) => {
|
|
1127
|
-
prev
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
};
|
|
1132
|
-
});
|
|
1116
|
+
updateMatch(matchId, (prev) => ({
|
|
1117
|
+
...prev,
|
|
1118
|
+
loaderPromise: void 0,
|
|
1119
|
+
...head
|
|
1120
|
+
}));
|
|
1133
1121
|
handleRedirectAndNotFound(this.getMatch(matchId), err);
|
|
1134
1122
|
}
|
|
1135
1123
|
};
|
|
@@ -1139,13 +1127,15 @@ class RouterCore {
|
|
|
1139
1127
|
} else if (loaderShouldRunAsync && !sync) {
|
|
1140
1128
|
loaderIsRunningAsync = true;
|
|
1141
1129
|
(async () => {
|
|
1142
|
-
var _a3, _b3;
|
|
1143
1130
|
try {
|
|
1144
1131
|
await runLoader();
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1132
|
+
const { loaderPromise, loadPromise } = this.getMatch(matchId);
|
|
1133
|
+
loaderPromise?.resolve();
|
|
1134
|
+
loadPromise?.resolve();
|
|
1135
|
+
updateMatch(matchId, (prev) => ({
|
|
1136
|
+
...prev,
|
|
1137
|
+
loaderPromise: void 0
|
|
1138
|
+
}));
|
|
1149
1139
|
} catch (err) {
|
|
1150
1140
|
if (isRedirect(err)) {
|
|
1151
1141
|
await this.navigate(err.options);
|
|
@@ -1163,20 +1153,19 @@ class RouterCore {
|
|
|
1163
1153
|
}
|
|
1164
1154
|
}
|
|
1165
1155
|
if (!loaderIsRunningAsync) {
|
|
1166
|
-
const
|
|
1167
|
-
|
|
1168
|
-
|
|
1156
|
+
const { loaderPromise, loadPromise } = this.getMatch(matchId);
|
|
1157
|
+
loaderPromise?.resolve();
|
|
1158
|
+
loadPromise?.resolve();
|
|
1169
1159
|
}
|
|
1170
1160
|
updateMatch(matchId, (prev) => {
|
|
1171
|
-
clearTimeout(prev.
|
|
1172
|
-
prev._nonReactive.pendingTimeout = void 0;
|
|
1173
|
-
if (!loaderIsRunningAsync)
|
|
1174
|
-
prev._nonReactive.loaderPromise = void 0;
|
|
1175
|
-
prev._nonReactive.dehydrated = void 0;
|
|
1161
|
+
clearTimeout(prev.pendingTimeout);
|
|
1176
1162
|
return {
|
|
1177
1163
|
...prev,
|
|
1178
1164
|
isFetching: loaderIsRunningAsync ? prev.isFetching : false,
|
|
1179
|
-
|
|
1165
|
+
loaderPromise: loaderIsRunningAsync ? prev.loaderPromise : void 0,
|
|
1166
|
+
invalid: false,
|
|
1167
|
+
pendingTimeout: void 0,
|
|
1168
|
+
_dehydrated: void 0
|
|
1180
1169
|
};
|
|
1181
1170
|
});
|
|
1182
1171
|
return this.getMatch(matchId);
|
|
@@ -1203,27 +1192,23 @@ class RouterCore {
|
|
|
1203
1192
|
};
|
|
1204
1193
|
this.invalidate = (opts) => {
|
|
1205
1194
|
const invalidate = (d) => {
|
|
1206
|
-
|
|
1207
|
-
if (((_a = opts == null ? void 0 : opts.filter) == null ? void 0 : _a.call(opts, d)) ?? true) {
|
|
1195
|
+
if (opts?.filter?.(d) ?? true) {
|
|
1208
1196
|
return {
|
|
1209
1197
|
...d,
|
|
1210
1198
|
invalid: true,
|
|
1211
|
-
...
|
|
1199
|
+
...opts?.forcePending || d.status === "error" ? { status: "pending", error: void 0 } : {}
|
|
1212
1200
|
};
|
|
1213
1201
|
}
|
|
1214
1202
|
return d;
|
|
1215
1203
|
};
|
|
1216
|
-
this.__store.setState((s) => {
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
pendingMatches: (_a = s.pendingMatches) == null ? void 0 : _a.map(invalidate)
|
|
1223
|
-
};
|
|
1224
|
-
});
|
|
1204
|
+
this.__store.setState((s) => ({
|
|
1205
|
+
...s,
|
|
1206
|
+
matches: s.matches.map(invalidate),
|
|
1207
|
+
cachedMatches: s.cachedMatches.map(invalidate),
|
|
1208
|
+
pendingMatches: s.pendingMatches?.map(invalidate)
|
|
1209
|
+
}));
|
|
1225
1210
|
this.shouldViewTransition = false;
|
|
1226
|
-
return this.load({ sync: opts
|
|
1211
|
+
return this.load({ sync: opts?.sync });
|
|
1227
1212
|
};
|
|
1228
1213
|
this.resolveRedirect = (redirect2) => {
|
|
1229
1214
|
if (!redirect2.options.href) {
|
|
@@ -1236,7 +1221,7 @@ class RouterCore {
|
|
|
1236
1221
|
return redirect2;
|
|
1237
1222
|
};
|
|
1238
1223
|
this.clearCache = (opts) => {
|
|
1239
|
-
const filter = opts
|
|
1224
|
+
const filter = opts?.filter;
|
|
1240
1225
|
if (filter !== void 0) {
|
|
1241
1226
|
this.__store.setState((s) => {
|
|
1242
1227
|
return {
|
|
@@ -1285,7 +1270,7 @@ class RouterCore {
|
|
|
1285
1270
|
() => Promise.all(
|
|
1286
1271
|
componentTypes.map(async (type) => {
|
|
1287
1272
|
const component = route.options[type];
|
|
1288
|
-
if (component
|
|
1273
|
+
if (component?.preload) {
|
|
1289
1274
|
await component.preload();
|
|
1290
1275
|
}
|
|
1291
1276
|
})
|
|
@@ -1361,10 +1346,10 @@ class RouterCore {
|
|
|
1361
1346
|
leaveParams: true
|
|
1362
1347
|
};
|
|
1363
1348
|
const next = this.buildLocation(matchLocation);
|
|
1364
|
-
if (
|
|
1349
|
+
if (opts?.pending && this.state.status !== "pending") {
|
|
1365
1350
|
return false;
|
|
1366
1351
|
}
|
|
1367
|
-
const pending =
|
|
1352
|
+
const pending = opts?.pending === void 0 ? !this.state.isLoading : opts.pending;
|
|
1368
1353
|
const baseLocation = pending ? this.latestLocation : this.state.resolvedLocation || this.state.location;
|
|
1369
1354
|
const match = matchPathname(
|
|
1370
1355
|
this.basepath,
|
|
@@ -1383,7 +1368,7 @@ class RouterCore {
|
|
|
1383
1368
|
return false;
|
|
1384
1369
|
}
|
|
1385
1370
|
}
|
|
1386
|
-
if (match && (
|
|
1371
|
+
if (match && (opts?.includeSearch ?? true)) {
|
|
1387
1372
|
return deepEqual(baseLocation.search, next.search, { partial: true }) ? match : false;
|
|
1388
1373
|
}
|
|
1389
1374
|
return match;
|
|
@@ -1391,13 +1376,12 @@ class RouterCore {
|
|
|
1391
1376
|
this._handleNotFound = (matches, err, {
|
|
1392
1377
|
updateMatch = this.updateMatch
|
|
1393
1378
|
} = {}) => {
|
|
1394
|
-
var _a;
|
|
1395
1379
|
const routeCursor = this.routesById[err.routeId ?? ""] ?? this.routeTree;
|
|
1396
1380
|
const matchesByRouteId = {};
|
|
1397
1381
|
for (const match of matches) {
|
|
1398
1382
|
matchesByRouteId[match.routeId] = match;
|
|
1399
1383
|
}
|
|
1400
|
-
if (!routeCursor.options.notFoundComponent &&
|
|
1384
|
+
if (!routeCursor.options.notFoundComponent && this.options?.defaultNotFoundComponent) {
|
|
1401
1385
|
routeCursor.options.notFoundComponent = this.options.defaultNotFoundComponent;
|
|
1402
1386
|
}
|
|
1403
1387
|
invariant(
|
|
@@ -1455,10 +1439,9 @@ class RouterCore {
|
|
|
1455
1439
|
return this.routesById;
|
|
1456
1440
|
}
|
|
1457
1441
|
matchRoutesInternal(next, opts) {
|
|
1458
|
-
var _a;
|
|
1459
1442
|
const { foundRoute, matchedRoutes, routeParams } = this.getMatchedRoutes(
|
|
1460
1443
|
next.pathname,
|
|
1461
|
-
|
|
1444
|
+
opts?.dest?.to
|
|
1462
1445
|
);
|
|
1463
1446
|
let isGlobalNotFound = false;
|
|
1464
1447
|
if (
|
|
@@ -1489,9 +1472,8 @@ class RouterCore {
|
|
|
1489
1472
|
return rootRouteId;
|
|
1490
1473
|
})();
|
|
1491
1474
|
const parseErrors = matchedRoutes.map((route) => {
|
|
1492
|
-
var _a2;
|
|
1493
1475
|
let parsedParamsError;
|
|
1494
|
-
const parseParams =
|
|
1476
|
+
const parseParams = route.options.params?.parse ?? route.options.parseParams;
|
|
1495
1477
|
if (parseParams) {
|
|
1496
1478
|
try {
|
|
1497
1479
|
const parsedParams = parseParams(routeParams);
|
|
@@ -1500,7 +1482,7 @@ class RouterCore {
|
|
|
1500
1482
|
parsedParamsError = new PathParamError(err.message, {
|
|
1501
1483
|
cause: err
|
|
1502
1484
|
});
|
|
1503
|
-
if (opts
|
|
1485
|
+
if (opts?.throwOnError) {
|
|
1504
1486
|
throw parsedParamsError;
|
|
1505
1487
|
}
|
|
1506
1488
|
return parsedParamsError;
|
|
@@ -1510,18 +1492,17 @@ class RouterCore {
|
|
|
1510
1492
|
});
|
|
1511
1493
|
const matches = [];
|
|
1512
1494
|
const getParentContext = (parentMatch) => {
|
|
1513
|
-
const parentMatchId = parentMatch
|
|
1514
|
-
const parentContext = !parentMatchId ? this.options.context ??
|
|
1495
|
+
const parentMatchId = parentMatch?.id;
|
|
1496
|
+
const parentContext = !parentMatchId ? this.options.context ?? {} : parentMatch.context ?? this.options.context ?? {};
|
|
1515
1497
|
return parentContext;
|
|
1516
1498
|
};
|
|
1517
1499
|
matchedRoutes.forEach((route, index) => {
|
|
1518
|
-
var _a2, _b;
|
|
1519
1500
|
const parentMatch = matches[index - 1];
|
|
1520
1501
|
const [preMatchSearch, strictMatchSearch, searchError] = (() => {
|
|
1521
|
-
const parentSearch =
|
|
1522
|
-
const parentStrictSearch =
|
|
1502
|
+
const parentSearch = parentMatch?.search ?? next.search;
|
|
1503
|
+
const parentStrictSearch = parentMatch?._strictSearch ?? {};
|
|
1523
1504
|
try {
|
|
1524
|
-
const strictSearch = validateSearch(route.options.validateSearch, { ...parentSearch }) ??
|
|
1505
|
+
const strictSearch = validateSearch(route.options.validateSearch, { ...parentSearch }) ?? {};
|
|
1525
1506
|
return [
|
|
1526
1507
|
{
|
|
1527
1508
|
...parentSearch,
|
|
@@ -1537,15 +1518,15 @@ class RouterCore {
|
|
|
1537
1518
|
cause: err
|
|
1538
1519
|
});
|
|
1539
1520
|
}
|
|
1540
|
-
if (opts
|
|
1521
|
+
if (opts?.throwOnError) {
|
|
1541
1522
|
throw searchParamError;
|
|
1542
1523
|
}
|
|
1543
1524
|
return [parentSearch, {}, searchParamError];
|
|
1544
1525
|
}
|
|
1545
1526
|
})();
|
|
1546
|
-
const loaderDeps =
|
|
1527
|
+
const loaderDeps = route.options.loaderDeps?.({
|
|
1547
1528
|
search: preMatchSearch
|
|
1548
|
-
})
|
|
1529
|
+
}) ?? "";
|
|
1549
1530
|
const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : "";
|
|
1550
1531
|
const { usedParams, interpolatedPath } = interpolatePath({
|
|
1551
1532
|
path: route.fullPath,
|
|
@@ -1591,10 +1572,7 @@ class RouterCore {
|
|
|
1591
1572
|
isFetching: false,
|
|
1592
1573
|
error: void 0,
|
|
1593
1574
|
paramsError: parseErrors[index],
|
|
1594
|
-
__routeContext:
|
|
1595
|
-
_nonReactive: {
|
|
1596
|
-
loadPromise: createControlledPromise()
|
|
1597
|
-
},
|
|
1575
|
+
__routeContext: {},
|
|
1598
1576
|
__beforeLoadContext: void 0,
|
|
1599
1577
|
context: {},
|
|
1600
1578
|
abortController: new AbortController(),
|
|
@@ -1608,10 +1586,11 @@ class RouterCore {
|
|
|
1608
1586
|
headScripts: void 0,
|
|
1609
1587
|
meta: void 0,
|
|
1610
1588
|
staticData: route.options.staticData || {},
|
|
1589
|
+
loadPromise: createControlledPromise(),
|
|
1611
1590
|
fullPath: route.fullPath
|
|
1612
1591
|
};
|
|
1613
1592
|
}
|
|
1614
|
-
if (!
|
|
1593
|
+
if (!opts?.preload) {
|
|
1615
1594
|
match.globalNotFound = globalNotFoundRouteId === route.id;
|
|
1616
1595
|
}
|
|
1617
1596
|
match.searchError = searchError;
|
|
@@ -1626,24 +1605,22 @@ class RouterCore {
|
|
|
1626
1605
|
matches.forEach((match, index) => {
|
|
1627
1606
|
const route = this.looseRoutesById[match.routeId];
|
|
1628
1607
|
const existingMatch = this.getMatch(match.id);
|
|
1629
|
-
if (!existingMatch &&
|
|
1608
|
+
if (!existingMatch && opts?._buildLocation !== true) {
|
|
1630
1609
|
const parentMatch = matches[index - 1];
|
|
1631
1610
|
const parentContext = getParentContext(parentMatch);
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
match.__routeContext = route.options.context(contextFnContext) ?? void 0;
|
|
1646
|
-
}
|
|
1611
|
+
const contextFnContext = {
|
|
1612
|
+
deps: match.loaderDeps,
|
|
1613
|
+
params: match.params,
|
|
1614
|
+
context: parentContext,
|
|
1615
|
+
location: next,
|
|
1616
|
+
navigate: (opts2) => this.navigate({ ...opts2, _fromLocation: next }),
|
|
1617
|
+
buildLocation: this.buildLocation,
|
|
1618
|
+
cause: match.cause,
|
|
1619
|
+
abortController: match.abortController,
|
|
1620
|
+
preload: !!match.preload,
|
|
1621
|
+
matches
|
|
1622
|
+
};
|
|
1623
|
+
match.__routeContext = route.options.context?.(contextFnContext) ?? {};
|
|
1647
1624
|
match.context = {
|
|
1648
1625
|
...parentContext,
|
|
1649
1626
|
...match.__routeContext,
|
|
@@ -1709,9 +1686,8 @@ const componentTypes = [
|
|
|
1709
1686
|
"notFoundComponent"
|
|
1710
1687
|
];
|
|
1711
1688
|
function routeNeedsPreload(route) {
|
|
1712
|
-
var _a;
|
|
1713
1689
|
for (const componentType of componentTypes) {
|
|
1714
|
-
if (
|
|
1690
|
+
if (route.options[componentType]?.preload) {
|
|
1715
1691
|
return true;
|
|
1716
1692
|
}
|
|
1717
1693
|
}
|
|
@@ -1745,7 +1721,7 @@ function processRouteTree({
|
|
|
1745
1721
|
const routesByPath = {};
|
|
1746
1722
|
const recurseRoutes = (childRoutes) => {
|
|
1747
1723
|
childRoutes.forEach((childRoute, i) => {
|
|
1748
|
-
initRoute
|
|
1724
|
+
initRoute?.(childRoute, i);
|
|
1749
1725
|
const existingRoute = routesById[childRoute.id];
|
|
1750
1726
|
invariant(
|
|
1751
1727
|
!existingRoute,
|
|
@@ -1759,7 +1735,7 @@ function processRouteTree({
|
|
|
1759
1735
|
}
|
|
1760
1736
|
}
|
|
1761
1737
|
const children = childRoute.children;
|
|
1762
|
-
if (children
|
|
1738
|
+
if (children?.length) {
|
|
1763
1739
|
recurseRoutes(children);
|
|
1764
1740
|
}
|
|
1765
1741
|
});
|
|
@@ -1768,14 +1744,13 @@ function processRouteTree({
|
|
|
1768
1744
|
const scoredRoutes = [];
|
|
1769
1745
|
const routes = Object.values(routesById);
|
|
1770
1746
|
routes.forEach((d, i) => {
|
|
1771
|
-
var _a;
|
|
1772
1747
|
if (d.isRoot || !d.path) {
|
|
1773
1748
|
return;
|
|
1774
1749
|
}
|
|
1775
1750
|
const trimmed = trimPathLeft(d.fullPath);
|
|
1776
1751
|
let parsed = parsePathname(trimmed);
|
|
1777
1752
|
let skip = 0;
|
|
1778
|
-
while (parsed.length > skip + 1 &&
|
|
1753
|
+
while (parsed.length > skip + 1 && parsed[skip]?.value === "/") {
|
|
1779
1754
|
skip++;
|
|
1780
1755
|
}
|
|
1781
1756
|
if (skip > 0) parsed = parsed.slice(skip);
|
|
@@ -1860,13 +1835,12 @@ function getMatchedRoutes({
|
|
|
1860
1835
|
let routeParams = {};
|
|
1861
1836
|
const trimmedPath = trimPathRight(pathname);
|
|
1862
1837
|
const getMatchedParams = (route) => {
|
|
1863
|
-
var _a;
|
|
1864
1838
|
const result = matchPathname(
|
|
1865
1839
|
basepath,
|
|
1866
1840
|
trimmedPath,
|
|
1867
1841
|
{
|
|
1868
1842
|
to: route.fullPath,
|
|
1869
|
-
caseSensitive:
|
|
1843
|
+
caseSensitive: route.options?.caseSensitive ?? caseSensitive,
|
|
1870
1844
|
// we need fuzzy matching for `notFoundMode: 'fuzzy'`
|
|
1871
1845
|
fuzzy: true
|
|
1872
1846
|
},
|
|
@@ -1915,10 +1889,9 @@ function applySearchMiddleware({
|
|
|
1915
1889
|
}) {
|
|
1916
1890
|
const allMiddlewares = destRoutes.reduce(
|
|
1917
1891
|
(acc, route) => {
|
|
1918
|
-
var _a;
|
|
1919
1892
|
const middlewares = [];
|
|
1920
1893
|
if ("search" in route.options) {
|
|
1921
|
-
if (
|
|
1894
|
+
if (route.options.search?.middlewares) {
|
|
1922
1895
|
middlewares.push(...route.options.search.middlewares);
|
|
1923
1896
|
}
|
|
1924
1897
|
} else if (route.options.preSearchFilters || route.options.postSearchFilters) {
|
|
@@ -1950,7 +1923,7 @@ function applySearchMiddleware({
|
|
|
1950
1923
|
try {
|
|
1951
1924
|
const validatedSearch = {
|
|
1952
1925
|
...result,
|
|
1953
|
-
...validateSearch(route.options.validateSearch, result) ??
|
|
1926
|
+
...validateSearch(route.options.validateSearch, result) ?? {}
|
|
1954
1927
|
};
|
|
1955
1928
|
return validatedSearch;
|
|
1956
1929
|
} catch {
|