@tanstack/router-core 1.120.4-alpha.19 → 1.120.5
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/fileRoute.d.cts +2 -6
- package/dist/cjs/index.cjs +0 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +6 -6
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +1 -18
- package/dist/cjs/path.cjs +16 -130
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/path.d.cts +0 -17
- package/dist/cjs/redirect.cjs +14 -17
- package/dist/cjs/redirect.cjs.map +1 -1
- package/dist/cjs/redirect.d.cts +7 -13
- package/dist/cjs/route.cjs +1 -12
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +16 -19
- package/dist/cjs/router.cjs +214 -287
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +3 -46
- package/dist/cjs/scroll-restoration.cjs +23 -12
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.d.cts +1 -1
- package/dist/cjs/typePrimitives.d.cts +2 -2
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +0 -2
- package/dist/esm/fileRoute.d.ts +2 -6
- package/dist/esm/index.d.ts +6 -6
- package/dist/esm/index.js +2 -5
- package/dist/esm/link.d.ts +1 -18
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/path.d.ts +0 -17
- package/dist/esm/path.js +16 -130
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/redirect.d.ts +7 -13
- package/dist/esm/redirect.js +14 -17
- package/dist/esm/redirect.js.map +1 -1
- package/dist/esm/route.d.ts +16 -19
- package/dist/esm/route.js +1 -12
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +3 -46
- package/dist/esm/router.js +217 -290
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration.d.ts +1 -1
- package/dist/esm/scroll-restoration.js +23 -12
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/typePrimitives.d.ts +2 -2
- package/dist/esm/utils.d.ts +0 -2
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/fileRoute.ts +1 -90
- package/src/index.ts +6 -14
- package/src/link.ts +11 -97
- package/src/path.ts +16 -181
- package/src/redirect.ts +22 -37
- package/src/route.ts +50 -108
- package/src/router.ts +270 -392
- package/src/scroll-restoration.ts +44 -27
- package/src/typePrimitives.ts +2 -2
- package/src/utils.ts +0 -14
package/dist/esm/router.js
CHANGED
|
@@ -2,12 +2,12 @@ import { Store, batch } from "@tanstack/store";
|
|
|
2
2
|
import { createMemoryHistory, createBrowserHistory, parseHref } from "@tanstack/history";
|
|
3
3
|
import invariant from "tiny-invariant";
|
|
4
4
|
import { pick, createControlledPromise, deepEqual, replaceEqualDeep, last, functionalUpdate } from "./utils.js";
|
|
5
|
-
import { trimPath, resolvePath, cleanPath,
|
|
5
|
+
import { trimPath, trimPathLeft, parsePathname, resolvePath, cleanPath, trimPathRight, matchPathname, interpolatePath, joinPaths } from "./path.js";
|
|
6
6
|
import { isNotFound } from "./not-found.js";
|
|
7
7
|
import { setupScrollRestoration } from "./scroll-restoration.js";
|
|
8
8
|
import { defaultParseSearch, defaultStringifySearch } from "./searchParams.js";
|
|
9
9
|
import { rootRouteId } from "./root.js";
|
|
10
|
-
import { isRedirect } from "./redirect.js";
|
|
10
|
+
import { isResolvedRedirect, isRedirect } from "./redirect.js";
|
|
11
11
|
function defaultSerializeError(err) {
|
|
12
12
|
if (err instanceof Error) {
|
|
13
13
|
const obj = {
|
|
@@ -46,7 +46,6 @@ class RouterCore {
|
|
|
46
46
|
this.isScrollRestoring = false;
|
|
47
47
|
this.isScrollRestorationSetup = false;
|
|
48
48
|
this.startTransition = (fn) => fn();
|
|
49
|
-
this.isShell = false;
|
|
50
49
|
this.update = (newOptions) => {
|
|
51
50
|
var _a;
|
|
52
51
|
if (newOptions.notFoundRoute) {
|
|
@@ -73,7 +72,10 @@ class RouterCore {
|
|
|
73
72
|
this.basepath = `/${trimPath(newOptions.basepath)}`;
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
|
-
if (
|
|
75
|
+
if (
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
77
|
+
!this.history || this.options.history && this.options.history !== this.history
|
|
78
|
+
) {
|
|
77
79
|
this.history = this.options.history ?? (this.isServer ? createMemoryHistory({
|
|
78
80
|
initialEntries: [this.basepath || "/"]
|
|
79
81
|
}) : createBrowserHistory());
|
|
@@ -96,28 +98,16 @@ class RouterCore {
|
|
|
96
98
|
});
|
|
97
99
|
setupScrollRestoration(this);
|
|
98
100
|
}
|
|
99
|
-
if (typeof window !== "undefined" && "CSS" in window &&
|
|
101
|
+
if (typeof window !== "undefined" && "CSS" in window && // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
102
|
+
typeof ((_a = window.CSS) == null ? void 0 : _a.supports) === "function") {
|
|
100
103
|
this.isViewTransitionTypesSupported = window.CSS.supports(
|
|
101
104
|
"selector(:active-view-transition-type(a)"
|
|
102
105
|
);
|
|
103
106
|
}
|
|
104
|
-
if (this.latestLocation.search.__TSS_SHELL) {
|
|
105
|
-
this.isShell = true;
|
|
106
|
-
}
|
|
107
107
|
};
|
|
108
108
|
this.buildRouteTree = () => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
initRoute: (route, i) => {
|
|
112
|
-
route.init({
|
|
113
|
-
originalIndex: i,
|
|
114
|
-
defaultSsr: this.options.defaultSsr
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
this.routesById = routesById;
|
|
119
|
-
this.routesByPath = routesByPath;
|
|
120
|
-
this.flatRoutes = flatRoutes;
|
|
109
|
+
this.routesById = {};
|
|
110
|
+
this.routesByPath = {};
|
|
121
111
|
const notFoundRoute = this.options.notFoundRoute;
|
|
122
112
|
if (notFoundRoute) {
|
|
123
113
|
notFoundRoute.init({
|
|
@@ -126,6 +116,77 @@ class RouterCore {
|
|
|
126
116
|
});
|
|
127
117
|
this.routesById[notFoundRoute.id] = notFoundRoute;
|
|
128
118
|
}
|
|
119
|
+
const recurseRoutes = (childRoutes) => {
|
|
120
|
+
childRoutes.forEach((childRoute, i) => {
|
|
121
|
+
childRoute.init({
|
|
122
|
+
originalIndex: i,
|
|
123
|
+
defaultSsr: this.options.defaultSsr
|
|
124
|
+
});
|
|
125
|
+
const existingRoute = this.routesById[childRoute.id];
|
|
126
|
+
invariant(
|
|
127
|
+
!existingRoute,
|
|
128
|
+
`Duplicate routes found with id: ${String(childRoute.id)}`
|
|
129
|
+
);
|
|
130
|
+
this.routesById[childRoute.id] = childRoute;
|
|
131
|
+
if (!childRoute.isRoot && childRoute.path) {
|
|
132
|
+
const trimmedFullPath = trimPathRight(childRoute.fullPath);
|
|
133
|
+
if (!this.routesByPath[trimmedFullPath] || childRoute.fullPath.endsWith("/")) {
|
|
134
|
+
this.routesByPath[trimmedFullPath] = childRoute;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const children = childRoute.children;
|
|
138
|
+
if (children == null ? void 0 : children.length) {
|
|
139
|
+
recurseRoutes(children);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
recurseRoutes([this.routeTree]);
|
|
144
|
+
const scoredRoutes = [];
|
|
145
|
+
const routes = Object.values(this.routesById);
|
|
146
|
+
routes.forEach((d, i) => {
|
|
147
|
+
var _a;
|
|
148
|
+
if (d.isRoot || !d.path) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const trimmed = trimPathLeft(d.fullPath);
|
|
152
|
+
const parsed = parsePathname(trimmed);
|
|
153
|
+
while (parsed.length > 1 && ((_a = parsed[0]) == null ? void 0 : _a.value) === "/") {
|
|
154
|
+
parsed.shift();
|
|
155
|
+
}
|
|
156
|
+
const scores = parsed.map((segment) => {
|
|
157
|
+
if (segment.value === "/") {
|
|
158
|
+
return 0.75;
|
|
159
|
+
}
|
|
160
|
+
if (segment.type === "param") {
|
|
161
|
+
return 0.5;
|
|
162
|
+
}
|
|
163
|
+
if (segment.type === "wildcard") {
|
|
164
|
+
return 0.25;
|
|
165
|
+
}
|
|
166
|
+
return 1;
|
|
167
|
+
});
|
|
168
|
+
scoredRoutes.push({ child: d, trimmed, parsed, index: i, scores });
|
|
169
|
+
});
|
|
170
|
+
this.flatRoutes = scoredRoutes.sort((a, b) => {
|
|
171
|
+
const minLength = Math.min(a.scores.length, b.scores.length);
|
|
172
|
+
for (let i = 0; i < minLength; i++) {
|
|
173
|
+
if (a.scores[i] !== b.scores[i]) {
|
|
174
|
+
return b.scores[i] - a.scores[i];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (a.scores.length !== b.scores.length) {
|
|
178
|
+
return b.scores.length - a.scores.length;
|
|
179
|
+
}
|
|
180
|
+
for (let i = 0; i < minLength; i++) {
|
|
181
|
+
if (a.parsed[i].value !== b.parsed[i].value) {
|
|
182
|
+
return a.parsed[i].value > b.parsed[i].value ? 1 : -1;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return a.index - b.index;
|
|
186
|
+
}).map((d, i) => {
|
|
187
|
+
d.child.rank = i;
|
|
188
|
+
return d.child;
|
|
189
|
+
});
|
|
129
190
|
};
|
|
130
191
|
this.subscribe = (eventType, fn) => {
|
|
131
192
|
const listener = {
|
|
@@ -198,16 +259,37 @@ class RouterCore {
|
|
|
198
259
|
return this.matchRoutesInternal(pathnameOrNext, locationSearchOrOpts);
|
|
199
260
|
}
|
|
200
261
|
};
|
|
201
|
-
this.getMatchedRoutes = (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
262
|
+
this.getMatchedRoutes = (next, dest) => {
|
|
263
|
+
let routeParams = {};
|
|
264
|
+
const trimmedPath = trimPathRight(next.pathname);
|
|
265
|
+
const getMatchedParams = (route) => {
|
|
266
|
+
const result = matchPathname(this.basepath, trimmedPath, {
|
|
267
|
+
to: route.fullPath,
|
|
268
|
+
caseSensitive: route.options.caseSensitive ?? this.options.caseSensitive,
|
|
269
|
+
fuzzy: true
|
|
270
|
+
});
|
|
271
|
+
return result;
|
|
272
|
+
};
|
|
273
|
+
let foundRoute = (dest == null ? void 0 : dest.to) !== void 0 ? this.routesByPath[dest.to] : void 0;
|
|
274
|
+
if (foundRoute) {
|
|
275
|
+
routeParams = getMatchedParams(foundRoute);
|
|
276
|
+
} else {
|
|
277
|
+
foundRoute = this.flatRoutes.find((route) => {
|
|
278
|
+
const matchedParams = getMatchedParams(route);
|
|
279
|
+
if (matchedParams) {
|
|
280
|
+
routeParams = matchedParams;
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
return false;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
let routeCursor = foundRoute || this.routesById[rootRouteId];
|
|
287
|
+
const matchedRoutes = [routeCursor];
|
|
288
|
+
while (routeCursor.parentRoute) {
|
|
289
|
+
routeCursor = routeCursor.parentRoute;
|
|
290
|
+
matchedRoutes.unshift(routeCursor);
|
|
291
|
+
}
|
|
292
|
+
return { matchedRoutes, routeParams, foundRoute };
|
|
211
293
|
};
|
|
212
294
|
this.cancelMatch = (id) => {
|
|
213
295
|
const match = this.getMatch(id);
|
|
@@ -420,16 +502,10 @@ class RouterCore {
|
|
|
420
502
|
maskedNext = build(maskedDest);
|
|
421
503
|
}
|
|
422
504
|
}
|
|
423
|
-
const nextMatches = this.getMatchedRoutes(
|
|
424
|
-
next.pathname,
|
|
425
|
-
dest.to
|
|
426
|
-
);
|
|
505
|
+
const nextMatches = this.getMatchedRoutes(next, dest);
|
|
427
506
|
const final = build(dest, nextMatches);
|
|
428
507
|
if (maskedNext) {
|
|
429
|
-
const maskedMatches = this.getMatchedRoutes(
|
|
430
|
-
maskedNext.pathname,
|
|
431
|
-
maskedDest == null ? void 0 : maskedDest.to
|
|
432
|
-
);
|
|
508
|
+
const maskedMatches = this.getMatchedRoutes(maskedNext, maskedDest);
|
|
433
509
|
const maskedFinal = build(maskedDest, maskedMatches);
|
|
434
510
|
final.maskedLocation = maskedFinal;
|
|
435
511
|
}
|
|
@@ -540,13 +616,6 @@ class RouterCore {
|
|
|
540
616
|
});
|
|
541
617
|
};
|
|
542
618
|
this.navigate = ({ to, reloadDocument, href, ...rest }) => {
|
|
543
|
-
if (!reloadDocument && href) {
|
|
544
|
-
try {
|
|
545
|
-
new URL(`${href}`);
|
|
546
|
-
reloadDocument = true;
|
|
547
|
-
} catch {
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
619
|
if (reloadDocument) {
|
|
551
620
|
if (!href) {
|
|
552
621
|
const location = this.buildLocation({ to, ...rest });
|
|
@@ -565,23 +634,8 @@ class RouterCore {
|
|
|
565
634
|
to
|
|
566
635
|
});
|
|
567
636
|
};
|
|
568
|
-
this.beforeLoad = () => {
|
|
569
|
-
this.cancelMatches();
|
|
570
|
-
this.latestLocation = this.parseLocation(this.latestLocation);
|
|
571
|
-
const pendingMatches = this.matchRoutes(this.latestLocation);
|
|
572
|
-
this.__store.setState((s) => ({
|
|
573
|
-
...s,
|
|
574
|
-
status: "pending",
|
|
575
|
-
isLoading: true,
|
|
576
|
-
location: this.latestLocation,
|
|
577
|
-
pendingMatches,
|
|
578
|
-
// If a cached moved to pendingMatches, remove it from cachedMatches
|
|
579
|
-
cachedMatches: s.cachedMatches.filter((d) => {
|
|
580
|
-
return !pendingMatches.find((e) => e.id === d.id);
|
|
581
|
-
})
|
|
582
|
-
}));
|
|
583
|
-
};
|
|
584
637
|
this.load = async (opts) => {
|
|
638
|
+
this.latestLocation = this.parseLocation(this.latestLocation);
|
|
585
639
|
let redirect;
|
|
586
640
|
let notFound;
|
|
587
641
|
let loadPromise;
|
|
@@ -589,9 +643,24 @@ class RouterCore {
|
|
|
589
643
|
this.startTransition(async () => {
|
|
590
644
|
var _a;
|
|
591
645
|
try {
|
|
592
|
-
this.beforeLoad();
|
|
593
646
|
const next = this.latestLocation;
|
|
594
647
|
const prevLocation = this.state.resolvedLocation;
|
|
648
|
+
this.cancelMatches();
|
|
649
|
+
let pendingMatches;
|
|
650
|
+
batch(() => {
|
|
651
|
+
pendingMatches = this.matchRoutes(next);
|
|
652
|
+
this.__store.setState((s) => ({
|
|
653
|
+
...s,
|
|
654
|
+
status: "pending",
|
|
655
|
+
isLoading: true,
|
|
656
|
+
location: next,
|
|
657
|
+
pendingMatches,
|
|
658
|
+
// If a cached moved to pendingMatches, remove it from cachedMatches
|
|
659
|
+
cachedMatches: s.cachedMatches.filter((d) => {
|
|
660
|
+
return !pendingMatches.find((e) => e.id === d.id);
|
|
661
|
+
})
|
|
662
|
+
}));
|
|
663
|
+
});
|
|
595
664
|
if (!this.state.redirect) {
|
|
596
665
|
this.emit({
|
|
597
666
|
type: "onBeforeNavigate",
|
|
@@ -610,7 +679,7 @@ class RouterCore {
|
|
|
610
679
|
});
|
|
611
680
|
await this.loadMatches({
|
|
612
681
|
sync: opts == null ? void 0 : opts.sync,
|
|
613
|
-
matches:
|
|
682
|
+
matches: pendingMatches,
|
|
614
683
|
location: next,
|
|
615
684
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
616
685
|
onReady: async () => {
|
|
@@ -659,11 +728,11 @@ class RouterCore {
|
|
|
659
728
|
}
|
|
660
729
|
});
|
|
661
730
|
} catch (err) {
|
|
662
|
-
if (
|
|
731
|
+
if (isResolvedRedirect(err)) {
|
|
663
732
|
redirect = err;
|
|
664
733
|
if (!this.isServer) {
|
|
665
734
|
this.navigate({
|
|
666
|
-
...redirect
|
|
735
|
+
...redirect,
|
|
667
736
|
replace: true,
|
|
668
737
|
ignoreBlocker: true
|
|
669
738
|
});
|
|
@@ -673,7 +742,7 @@ class RouterCore {
|
|
|
673
742
|
}
|
|
674
743
|
this.__store.setState((s) => ({
|
|
675
744
|
...s,
|
|
676
|
-
statusCode: redirect ? redirect.
|
|
745
|
+
statusCode: redirect ? redirect.statusCode : notFound ? 404 : s.matches.some((d) => d.status === "error") ? 500 : 200,
|
|
677
746
|
redirect
|
|
678
747
|
}));
|
|
679
748
|
}
|
|
@@ -771,14 +840,12 @@ class RouterCore {
|
|
|
771
840
|
};
|
|
772
841
|
const handleRedirectAndNotFound = (match, err) => {
|
|
773
842
|
var _a, _b, _c, _d;
|
|
774
|
-
if (
|
|
775
|
-
if (
|
|
776
|
-
|
|
777
|
-
if (!err.options.reloadDocument) {
|
|
778
|
-
throw err;
|
|
779
|
-
}
|
|
780
|
-
}
|
|
843
|
+
if (isResolvedRedirect(err)) {
|
|
844
|
+
if (!err.reloadDocument) {
|
|
845
|
+
throw err;
|
|
781
846
|
}
|
|
847
|
+
}
|
|
848
|
+
if (isRedirect(err) || isNotFound(err)) {
|
|
782
849
|
updateMatch(match.id, (prev) => ({
|
|
783
850
|
...prev,
|
|
784
851
|
status: isRedirect(err) ? "redirected" : isNotFound(err) ? "notFound" : "error",
|
|
@@ -795,9 +862,7 @@ class RouterCore {
|
|
|
795
862
|
(_c = match.loadPromise) == null ? void 0 : _c.resolve();
|
|
796
863
|
if (isRedirect(err)) {
|
|
797
864
|
rendered = true;
|
|
798
|
-
err.
|
|
799
|
-
err.redirectHandled = true;
|
|
800
|
-
err = this.resolveRedirect(err);
|
|
865
|
+
err = this.resolveRedirect({ ...err, _fromLocation: location });
|
|
801
866
|
throw err;
|
|
802
867
|
} else if (isNotFound(err)) {
|
|
803
868
|
this._handleNotFound(matches, err, {
|
|
@@ -1005,8 +1070,35 @@ class RouterCore {
|
|
|
1005
1070
|
loaderPromise: createControlledPromise(),
|
|
1006
1071
|
preload: !!preload && !this.state.matches.find((d) => d.id === matchId)
|
|
1007
1072
|
}));
|
|
1073
|
+
const executeHead = () => {
|
|
1074
|
+
var _a2, _b2, _c2, _d2, _e, _f;
|
|
1075
|
+
const match = this.getMatch(matchId);
|
|
1076
|
+
if (!match) {
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
const assetContext = {
|
|
1080
|
+
matches,
|
|
1081
|
+
match,
|
|
1082
|
+
params: match.params,
|
|
1083
|
+
loaderData: match.loaderData
|
|
1084
|
+
};
|
|
1085
|
+
const headFnContent = (_b2 = (_a2 = route.options).head) == null ? void 0 : _b2.call(_a2, assetContext);
|
|
1086
|
+
const meta = headFnContent == null ? void 0 : headFnContent.meta;
|
|
1087
|
+
const links = headFnContent == null ? void 0 : headFnContent.links;
|
|
1088
|
+
const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
|
|
1089
|
+
const scripts = (_d2 = (_c2 = route.options).scripts) == null ? void 0 : _d2.call(_c2, assetContext);
|
|
1090
|
+
const headers = (_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, assetContext);
|
|
1091
|
+
updateMatch(matchId, (prev) => ({
|
|
1092
|
+
...prev,
|
|
1093
|
+
meta,
|
|
1094
|
+
links,
|
|
1095
|
+
headScripts,
|
|
1096
|
+
headers,
|
|
1097
|
+
scripts
|
|
1098
|
+
}));
|
|
1099
|
+
};
|
|
1008
1100
|
const runLoader = async () => {
|
|
1009
|
-
var _a2, _b2, _c2, _d2, _e
|
|
1101
|
+
var _a2, _b2, _c2, _d2, _e;
|
|
1010
1102
|
try {
|
|
1011
1103
|
const potentialPendingMinPromise = async () => {
|
|
1012
1104
|
const latestMatch = this.getMatch(matchId);
|
|
@@ -1027,40 +1119,24 @@ class RouterCore {
|
|
|
1027
1119
|
);
|
|
1028
1120
|
await route._lazyPromise;
|
|
1029
1121
|
await potentialPendingMinPromise();
|
|
1030
|
-
const assetContext = {
|
|
1031
|
-
matches,
|
|
1032
|
-
match: this.getMatch(matchId),
|
|
1033
|
-
params: this.getMatch(matchId).params,
|
|
1034
|
-
loaderData
|
|
1035
|
-
};
|
|
1036
|
-
const headFnContent = (_d2 = (_c2 = route.options).head) == null ? void 0 : _d2.call(_c2, assetContext);
|
|
1037
|
-
const meta = headFnContent == null ? void 0 : headFnContent.meta;
|
|
1038
|
-
const links = headFnContent == null ? void 0 : headFnContent.links;
|
|
1039
|
-
const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
|
|
1040
|
-
const scripts = (_f = (_e = route.options).scripts) == null ? void 0 : _f.call(_e, assetContext);
|
|
1041
|
-
const headers = (_h = (_g = route.options).headers) == null ? void 0 : _h.call(_g, {
|
|
1042
|
-
loaderData
|
|
1043
|
-
});
|
|
1044
1122
|
await route._componentsPromise;
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
scripts
|
|
1057
|
-
}));
|
|
1123
|
+
batch(() => {
|
|
1124
|
+
updateMatch(matchId, (prev) => ({
|
|
1125
|
+
...prev,
|
|
1126
|
+
error: void 0,
|
|
1127
|
+
status: "success",
|
|
1128
|
+
isFetching: false,
|
|
1129
|
+
updatedAt: Date.now(),
|
|
1130
|
+
loaderData
|
|
1131
|
+
}));
|
|
1132
|
+
executeHead();
|
|
1133
|
+
});
|
|
1058
1134
|
} catch (e) {
|
|
1059
1135
|
let error = e;
|
|
1060
1136
|
await potentialPendingMinPromise();
|
|
1061
1137
|
handleRedirectAndNotFound(this.getMatch(matchId), e);
|
|
1062
1138
|
try {
|
|
1063
|
-
(
|
|
1139
|
+
(_d2 = (_c2 = route.options).onError) == null ? void 0 : _d2.call(_c2, e);
|
|
1064
1140
|
} catch (onErrorError) {
|
|
1065
1141
|
error = onErrorError;
|
|
1066
1142
|
handleRedirectAndNotFound(
|
|
@@ -1068,22 +1144,28 @@ class RouterCore {
|
|
|
1068
1144
|
onErrorError
|
|
1069
1145
|
);
|
|
1070
1146
|
}
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1147
|
+
batch(() => {
|
|
1148
|
+
updateMatch(matchId, (prev) => ({
|
|
1149
|
+
...prev,
|
|
1150
|
+
error,
|
|
1151
|
+
status: "error",
|
|
1152
|
+
isFetching: false
|
|
1153
|
+
}));
|
|
1154
|
+
executeHead();
|
|
1155
|
+
});
|
|
1077
1156
|
}
|
|
1078
|
-
(
|
|
1157
|
+
(_e = this.serverSsr) == null ? void 0 : _e.onMatchSettled({
|
|
1079
1158
|
router: this,
|
|
1080
1159
|
match: this.getMatch(matchId)
|
|
1081
1160
|
});
|
|
1082
1161
|
} catch (err) {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1162
|
+
batch(() => {
|
|
1163
|
+
updateMatch(matchId, (prev) => ({
|
|
1164
|
+
...prev,
|
|
1165
|
+
loaderPromise: void 0
|
|
1166
|
+
}));
|
|
1167
|
+
executeHead();
|
|
1168
|
+
});
|
|
1087
1169
|
handleRedirectAndNotFound(this.getMatch(matchId), err);
|
|
1088
1170
|
}
|
|
1089
1171
|
};
|
|
@@ -1103,13 +1185,15 @@ class RouterCore {
|
|
|
1103
1185
|
loaderPromise: void 0
|
|
1104
1186
|
}));
|
|
1105
1187
|
} catch (err) {
|
|
1106
|
-
if (
|
|
1107
|
-
await this.navigate(err
|
|
1188
|
+
if (isResolvedRedirect(err)) {
|
|
1189
|
+
await this.navigate(err);
|
|
1108
1190
|
}
|
|
1109
1191
|
}
|
|
1110
1192
|
})();
|
|
1111
1193
|
} else if (status !== "success" || loaderShouldRunAsync && sync) {
|
|
1112
1194
|
await runLoader();
|
|
1195
|
+
} else {
|
|
1196
|
+
executeHead();
|
|
1113
1197
|
}
|
|
1114
1198
|
}
|
|
1115
1199
|
if (!loaderIsRunningAsync) {
|
|
@@ -1168,13 +1252,10 @@ class RouterCore {
|
|
|
1168
1252
|
});
|
|
1169
1253
|
return this.load({ sync: opts == null ? void 0 : opts.sync });
|
|
1170
1254
|
};
|
|
1171
|
-
this.resolveRedirect = (
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
redirect.
|
|
1175
|
-
}
|
|
1176
|
-
if (!redirect.headers.get("Location")) {
|
|
1177
|
-
redirect.headers.set("Location", redirect.options.href);
|
|
1255
|
+
this.resolveRedirect = (err) => {
|
|
1256
|
+
const redirect = err;
|
|
1257
|
+
if (!redirect.href) {
|
|
1258
|
+
redirect.href = this.buildLocation(redirect).href;
|
|
1178
1259
|
}
|
|
1179
1260
|
return redirect;
|
|
1180
1261
|
};
|
|
@@ -1276,11 +1357,11 @@ class RouterCore {
|
|
|
1276
1357
|
return matches;
|
|
1277
1358
|
} catch (err) {
|
|
1278
1359
|
if (isRedirect(err)) {
|
|
1279
|
-
if (err.
|
|
1360
|
+
if (err.reloadDocument) {
|
|
1280
1361
|
return void 0;
|
|
1281
1362
|
}
|
|
1282
1363
|
return await this.preloadRoute({
|
|
1283
|
-
...err
|
|
1364
|
+
...err,
|
|
1284
1365
|
_fromLocation: next
|
|
1285
1366
|
});
|
|
1286
1367
|
}
|
|
@@ -1384,10 +1465,9 @@ class RouterCore {
|
|
|
1384
1465
|
return this.routesById;
|
|
1385
1466
|
}
|
|
1386
1467
|
matchRoutesInternal(next, opts) {
|
|
1387
|
-
var _a;
|
|
1388
1468
|
const { foundRoute, matchedRoutes, routeParams } = this.getMatchedRoutes(
|
|
1389
|
-
next
|
|
1390
|
-
|
|
1469
|
+
next,
|
|
1470
|
+
opts == null ? void 0 : opts.dest
|
|
1391
1471
|
);
|
|
1392
1472
|
let isGlobalNotFound = false;
|
|
1393
1473
|
if (
|
|
@@ -1418,9 +1498,9 @@ class RouterCore {
|
|
|
1418
1498
|
return rootRouteId;
|
|
1419
1499
|
})();
|
|
1420
1500
|
const parseErrors = matchedRoutes.map((route) => {
|
|
1421
|
-
var
|
|
1501
|
+
var _a;
|
|
1422
1502
|
let parsedParamsError;
|
|
1423
|
-
const parseParams = ((
|
|
1503
|
+
const parseParams = ((_a = route.options.params) == null ? void 0 : _a.parse) ?? route.options.parseParams;
|
|
1424
1504
|
if (parseParams) {
|
|
1425
1505
|
try {
|
|
1426
1506
|
const parsedParams = parseParams(routeParams);
|
|
@@ -1444,7 +1524,7 @@ class RouterCore {
|
|
|
1444
1524
|
return parentContext;
|
|
1445
1525
|
};
|
|
1446
1526
|
matchedRoutes.forEach((route, index) => {
|
|
1447
|
-
var
|
|
1527
|
+
var _a, _b;
|
|
1448
1528
|
const parentMatch = matches[index - 1];
|
|
1449
1529
|
const [preMatchSearch, strictMatchSearch, searchError] = (() => {
|
|
1450
1530
|
const parentSearch = (parentMatch == null ? void 0 : parentMatch.search) ?? next.search;
|
|
@@ -1472,7 +1552,7 @@ class RouterCore {
|
|
|
1472
1552
|
return [parentSearch, {}, searchParamError];
|
|
1473
1553
|
}
|
|
1474
1554
|
})();
|
|
1475
|
-
const loaderDeps = ((_b = (
|
|
1555
|
+
const loaderDeps = ((_b = (_a = route.options).loaderDeps) == null ? void 0 : _b.call(_a, {
|
|
1476
1556
|
search: preMatchSearch
|
|
1477
1557
|
})) ?? "";
|
|
1478
1558
|
const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : "";
|
|
@@ -1550,7 +1630,7 @@ class RouterCore {
|
|
|
1550
1630
|
matches.push(match);
|
|
1551
1631
|
});
|
|
1552
1632
|
matches.forEach((match, index) => {
|
|
1553
|
-
var
|
|
1633
|
+
var _a, _b;
|
|
1554
1634
|
const route = this.looseRoutesById[match.routeId];
|
|
1555
1635
|
const existingMatch = this.getMatch(match.id);
|
|
1556
1636
|
if (!existingMatch && (opts == null ? void 0 : opts._buildLocation) !== true) {
|
|
@@ -1568,29 +1648,13 @@ class RouterCore {
|
|
|
1568
1648
|
preload: !!match.preload,
|
|
1569
1649
|
matches
|
|
1570
1650
|
};
|
|
1571
|
-
match.__routeContext = ((_b = (
|
|
1651
|
+
match.__routeContext = ((_b = (_a = route.options).context) == null ? void 0 : _b.call(_a, contextFnContext)) ?? {};
|
|
1572
1652
|
match.context = {
|
|
1573
1653
|
...parentContext,
|
|
1574
1654
|
...match.__routeContext,
|
|
1575
1655
|
...match.__beforeLoadContext
|
|
1576
1656
|
};
|
|
1577
1657
|
}
|
|
1578
|
-
if (match.status === "success") {
|
|
1579
|
-
match.headers = (_d = (_c = route.options).headers) == null ? void 0 : _d.call(_c, {
|
|
1580
|
-
loaderData: match.loaderData
|
|
1581
|
-
});
|
|
1582
|
-
const assetContext = {
|
|
1583
|
-
matches,
|
|
1584
|
-
match,
|
|
1585
|
-
params: match.params,
|
|
1586
|
-
loaderData: match.loaderData
|
|
1587
|
-
};
|
|
1588
|
-
const headFnContent = (_f = (_e = route.options).head) == null ? void 0 : _f.call(_e, assetContext);
|
|
1589
|
-
match.links = headFnContent == null ? void 0 : headFnContent.links;
|
|
1590
|
-
match.headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
|
|
1591
|
-
match.meta = headFnContent == null ? void 0 : headFnContent.meta;
|
|
1592
|
-
match.scripts = (_h = (_g = route.options).scripts) == null ? void 0 : _h.call(_g, assetContext);
|
|
1593
|
-
}
|
|
1594
1658
|
});
|
|
1595
1659
|
return matches;
|
|
1596
1660
|
}
|
|
@@ -1654,141 +1718,6 @@ function routeNeedsPreload(route) {
|
|
|
1654
1718
|
}
|
|
1655
1719
|
return false;
|
|
1656
1720
|
}
|
|
1657
|
-
function processRouteTree({
|
|
1658
|
-
routeTree,
|
|
1659
|
-
initRoute
|
|
1660
|
-
}) {
|
|
1661
|
-
const routesById = {};
|
|
1662
|
-
const routesByPath = {};
|
|
1663
|
-
const recurseRoutes = (childRoutes) => {
|
|
1664
|
-
childRoutes.forEach((childRoute, i) => {
|
|
1665
|
-
initRoute == null ? void 0 : initRoute(childRoute, i);
|
|
1666
|
-
const existingRoute = routesById[childRoute.id];
|
|
1667
|
-
invariant(
|
|
1668
|
-
!existingRoute,
|
|
1669
|
-
`Duplicate routes found with id: ${String(childRoute.id)}`
|
|
1670
|
-
);
|
|
1671
|
-
routesById[childRoute.id] = childRoute;
|
|
1672
|
-
if (!childRoute.isRoot && childRoute.path) {
|
|
1673
|
-
const trimmedFullPath = trimPathRight(childRoute.fullPath);
|
|
1674
|
-
if (!routesByPath[trimmedFullPath] || childRoute.fullPath.endsWith("/")) {
|
|
1675
|
-
routesByPath[trimmedFullPath] = childRoute;
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
const children = childRoute.children;
|
|
1679
|
-
if (children == null ? void 0 : children.length) {
|
|
1680
|
-
recurseRoutes(children);
|
|
1681
|
-
}
|
|
1682
|
-
});
|
|
1683
|
-
};
|
|
1684
|
-
recurseRoutes([routeTree]);
|
|
1685
|
-
const scoredRoutes = [];
|
|
1686
|
-
const routes = Object.values(routesById);
|
|
1687
|
-
routes.forEach((d, i) => {
|
|
1688
|
-
var _a;
|
|
1689
|
-
if (d.isRoot || !d.path) {
|
|
1690
|
-
return;
|
|
1691
|
-
}
|
|
1692
|
-
const trimmed = trimPathLeft(d.fullPath);
|
|
1693
|
-
const parsed = parsePathname(trimmed);
|
|
1694
|
-
while (parsed.length > 1 && ((_a = parsed[0]) == null ? void 0 : _a.value) === "/") {
|
|
1695
|
-
parsed.shift();
|
|
1696
|
-
}
|
|
1697
|
-
const scores = parsed.map((segment) => {
|
|
1698
|
-
if (segment.value === "/") {
|
|
1699
|
-
return 0.75;
|
|
1700
|
-
}
|
|
1701
|
-
if (segment.type === "param" && segment.prefixSegment && segment.suffixSegment) {
|
|
1702
|
-
return 0.55;
|
|
1703
|
-
}
|
|
1704
|
-
if (segment.type === "param" && segment.prefixSegment) {
|
|
1705
|
-
return 0.52;
|
|
1706
|
-
}
|
|
1707
|
-
if (segment.type === "param" && segment.suffixSegment) {
|
|
1708
|
-
return 0.51;
|
|
1709
|
-
}
|
|
1710
|
-
if (segment.type === "param") {
|
|
1711
|
-
return 0.5;
|
|
1712
|
-
}
|
|
1713
|
-
if (segment.type === "wildcard" && segment.prefixSegment && segment.suffixSegment) {
|
|
1714
|
-
return 0.3;
|
|
1715
|
-
}
|
|
1716
|
-
if (segment.type === "wildcard" && segment.prefixSegment) {
|
|
1717
|
-
return 0.27;
|
|
1718
|
-
}
|
|
1719
|
-
if (segment.type === "wildcard" && segment.suffixSegment) {
|
|
1720
|
-
return 0.26;
|
|
1721
|
-
}
|
|
1722
|
-
if (segment.type === "wildcard") {
|
|
1723
|
-
return 0.25;
|
|
1724
|
-
}
|
|
1725
|
-
return 1;
|
|
1726
|
-
});
|
|
1727
|
-
scoredRoutes.push({ child: d, trimmed, parsed, index: i, scores });
|
|
1728
|
-
});
|
|
1729
|
-
const flatRoutes = scoredRoutes.sort((a, b) => {
|
|
1730
|
-
const minLength = Math.min(a.scores.length, b.scores.length);
|
|
1731
|
-
for (let i = 0; i < minLength; i++) {
|
|
1732
|
-
if (a.scores[i] !== b.scores[i]) {
|
|
1733
|
-
return b.scores[i] - a.scores[i];
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
if (a.scores.length !== b.scores.length) {
|
|
1737
|
-
return b.scores.length - a.scores.length;
|
|
1738
|
-
}
|
|
1739
|
-
for (let i = 0; i < minLength; i++) {
|
|
1740
|
-
if (a.parsed[i].value !== b.parsed[i].value) {
|
|
1741
|
-
return a.parsed[i].value > b.parsed[i].value ? 1 : -1;
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
return a.index - b.index;
|
|
1745
|
-
}).map((d, i) => {
|
|
1746
|
-
d.child.rank = i;
|
|
1747
|
-
return d.child;
|
|
1748
|
-
});
|
|
1749
|
-
return { routesById, routesByPath, flatRoutes };
|
|
1750
|
-
}
|
|
1751
|
-
function getMatchedRoutes({
|
|
1752
|
-
pathname,
|
|
1753
|
-
routePathname,
|
|
1754
|
-
basepath,
|
|
1755
|
-
caseSensitive,
|
|
1756
|
-
routesByPath,
|
|
1757
|
-
routesById,
|
|
1758
|
-
flatRoutes
|
|
1759
|
-
}) {
|
|
1760
|
-
let routeParams = {};
|
|
1761
|
-
const trimmedPath = trimPathRight(pathname);
|
|
1762
|
-
const getMatchedParams = (route) => {
|
|
1763
|
-
var _a;
|
|
1764
|
-
const result = matchPathname(basepath, trimmedPath, {
|
|
1765
|
-
to: route.fullPath,
|
|
1766
|
-
caseSensitive: ((_a = route.options) == null ? void 0 : _a.caseSensitive) ?? caseSensitive,
|
|
1767
|
-
fuzzy: true
|
|
1768
|
-
});
|
|
1769
|
-
return result;
|
|
1770
|
-
};
|
|
1771
|
-
let foundRoute = routePathname !== void 0 ? routesByPath[routePathname] : void 0;
|
|
1772
|
-
if (foundRoute) {
|
|
1773
|
-
routeParams = getMatchedParams(foundRoute);
|
|
1774
|
-
} else {
|
|
1775
|
-
foundRoute = flatRoutes.find((route) => {
|
|
1776
|
-
const matchedParams = getMatchedParams(route);
|
|
1777
|
-
if (matchedParams) {
|
|
1778
|
-
routeParams = matchedParams;
|
|
1779
|
-
return true;
|
|
1780
|
-
}
|
|
1781
|
-
return false;
|
|
1782
|
-
});
|
|
1783
|
-
}
|
|
1784
|
-
let routeCursor = foundRoute || routesById[rootRouteId];
|
|
1785
|
-
const matchedRoutes = [routeCursor];
|
|
1786
|
-
while (routeCursor.parentRoute) {
|
|
1787
|
-
routeCursor = routeCursor.parentRoute;
|
|
1788
|
-
matchedRoutes.unshift(routeCursor);
|
|
1789
|
-
}
|
|
1790
|
-
return { matchedRoutes, routeParams, foundRoute };
|
|
1791
|
-
}
|
|
1792
1721
|
export {
|
|
1793
1722
|
PathParamError,
|
|
1794
1723
|
RouterCore,
|
|
@@ -1797,8 +1726,6 @@ export {
|
|
|
1797
1726
|
defaultSerializeError,
|
|
1798
1727
|
getInitialRouterState,
|
|
1799
1728
|
getLocationChangeInfo,
|
|
1800
|
-
|
|
1801
|
-
lazyFn,
|
|
1802
|
-
processRouteTree
|
|
1729
|
+
lazyFn
|
|
1803
1730
|
};
|
|
1804
1731
|
//# sourceMappingURL=router.js.map
|