@tanstack/router-core 1.120.4-alpha.15 → 1.120.4
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 -17
- 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 +14 -15
- package/dist/cjs/router.cjs +155 -231
- 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 -17
- 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 +14 -15
- 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 +158 -234
- 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 -96
- package/src/path.ts +16 -181
- package/src/redirect.ts +22 -37
- package/src/route.ts +35 -104
- package/src/router.ts +209 -332
- 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, {
|
|
@@ -1103,8 +1168,8 @@ class RouterCore {
|
|
|
1103
1168
|
loaderPromise: void 0
|
|
1104
1169
|
}));
|
|
1105
1170
|
} catch (err) {
|
|
1106
|
-
if (
|
|
1107
|
-
await this.navigate(err
|
|
1171
|
+
if (isResolvedRedirect(err)) {
|
|
1172
|
+
await this.navigate(err);
|
|
1108
1173
|
}
|
|
1109
1174
|
}
|
|
1110
1175
|
})();
|
|
@@ -1168,13 +1233,10 @@ class RouterCore {
|
|
|
1168
1233
|
});
|
|
1169
1234
|
return this.load({ sync: opts == null ? void 0 : opts.sync });
|
|
1170
1235
|
};
|
|
1171
|
-
this.resolveRedirect = (
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
redirect.
|
|
1175
|
-
}
|
|
1176
|
-
if (!redirect.headers.get("Location")) {
|
|
1177
|
-
redirect.headers.set("Location", redirect.options.href);
|
|
1236
|
+
this.resolveRedirect = (err) => {
|
|
1237
|
+
const redirect = err;
|
|
1238
|
+
if (!redirect.href) {
|
|
1239
|
+
redirect.href = this.buildLocation(redirect).href;
|
|
1178
1240
|
}
|
|
1179
1241
|
return redirect;
|
|
1180
1242
|
};
|
|
@@ -1276,11 +1338,11 @@ class RouterCore {
|
|
|
1276
1338
|
return matches;
|
|
1277
1339
|
} catch (err) {
|
|
1278
1340
|
if (isRedirect(err)) {
|
|
1279
|
-
if (err.
|
|
1341
|
+
if (err.reloadDocument) {
|
|
1280
1342
|
return void 0;
|
|
1281
1343
|
}
|
|
1282
1344
|
return await this.preloadRoute({
|
|
1283
|
-
...err
|
|
1345
|
+
...err,
|
|
1284
1346
|
_fromLocation: next
|
|
1285
1347
|
});
|
|
1286
1348
|
}
|
|
@@ -1384,10 +1446,9 @@ class RouterCore {
|
|
|
1384
1446
|
return this.routesById;
|
|
1385
1447
|
}
|
|
1386
1448
|
matchRoutesInternal(next, opts) {
|
|
1387
|
-
var _a;
|
|
1388
1449
|
const { foundRoute, matchedRoutes, routeParams } = this.getMatchedRoutes(
|
|
1389
|
-
next
|
|
1390
|
-
|
|
1450
|
+
next,
|
|
1451
|
+
opts == null ? void 0 : opts.dest
|
|
1391
1452
|
);
|
|
1392
1453
|
let isGlobalNotFound = false;
|
|
1393
1454
|
if (
|
|
@@ -1418,9 +1479,9 @@ class RouterCore {
|
|
|
1418
1479
|
return rootRouteId;
|
|
1419
1480
|
})();
|
|
1420
1481
|
const parseErrors = matchedRoutes.map((route) => {
|
|
1421
|
-
var
|
|
1482
|
+
var _a;
|
|
1422
1483
|
let parsedParamsError;
|
|
1423
|
-
const parseParams = ((
|
|
1484
|
+
const parseParams = ((_a = route.options.params) == null ? void 0 : _a.parse) ?? route.options.parseParams;
|
|
1424
1485
|
if (parseParams) {
|
|
1425
1486
|
try {
|
|
1426
1487
|
const parsedParams = parseParams(routeParams);
|
|
@@ -1444,7 +1505,7 @@ class RouterCore {
|
|
|
1444
1505
|
return parentContext;
|
|
1445
1506
|
};
|
|
1446
1507
|
matchedRoutes.forEach((route, index) => {
|
|
1447
|
-
var
|
|
1508
|
+
var _a, _b;
|
|
1448
1509
|
const parentMatch = matches[index - 1];
|
|
1449
1510
|
const [preMatchSearch, strictMatchSearch, searchError] = (() => {
|
|
1450
1511
|
const parentSearch = (parentMatch == null ? void 0 : parentMatch.search) ?? next.search;
|
|
@@ -1472,7 +1533,7 @@ class RouterCore {
|
|
|
1472
1533
|
return [parentSearch, {}, searchParamError];
|
|
1473
1534
|
}
|
|
1474
1535
|
})();
|
|
1475
|
-
const loaderDeps = ((_b = (
|
|
1536
|
+
const loaderDeps = ((_b = (_a = route.options).loaderDeps) == null ? void 0 : _b.call(_a, {
|
|
1476
1537
|
search: preMatchSearch
|
|
1477
1538
|
})) ?? "";
|
|
1478
1539
|
const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : "";
|
|
@@ -1550,7 +1611,7 @@ class RouterCore {
|
|
|
1550
1611
|
matches.push(match);
|
|
1551
1612
|
});
|
|
1552
1613
|
matches.forEach((match, index) => {
|
|
1553
|
-
var
|
|
1614
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1554
1615
|
const route = this.looseRoutesById[match.routeId];
|
|
1555
1616
|
const existingMatch = this.getMatch(match.id);
|
|
1556
1617
|
if (!existingMatch && (opts == null ? void 0 : opts._buildLocation) !== true) {
|
|
@@ -1568,7 +1629,7 @@ class RouterCore {
|
|
|
1568
1629
|
preload: !!match.preload,
|
|
1569
1630
|
matches
|
|
1570
1631
|
};
|
|
1571
|
-
match.__routeContext = ((_b = (
|
|
1632
|
+
match.__routeContext = ((_b = (_a = route.options).context) == null ? void 0 : _b.call(_a, contextFnContext)) ?? {};
|
|
1572
1633
|
match.context = {
|
|
1573
1634
|
...parentContext,
|
|
1574
1635
|
...match.__routeContext,
|
|
@@ -1654,141 +1715,6 @@ function routeNeedsPreload(route) {
|
|
|
1654
1715
|
}
|
|
1655
1716
|
return false;
|
|
1656
1717
|
}
|
|
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
1718
|
export {
|
|
1793
1719
|
PathParamError,
|
|
1794
1720
|
RouterCore,
|
|
@@ -1797,8 +1723,6 @@ export {
|
|
|
1797
1723
|
defaultSerializeError,
|
|
1798
1724
|
getInitialRouterState,
|
|
1799
1725
|
getLocationChangeInfo,
|
|
1800
|
-
|
|
1801
|
-
lazyFn,
|
|
1802
|
-
processRouteTree
|
|
1726
|
+
lazyFn
|
|
1803
1727
|
};
|
|
1804
1728
|
//# sourceMappingURL=router.js.map
|