@tanstack/router-core 1.120.4-alpha.19 → 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 -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 +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 -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 +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 -97
- 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/cjs/router.cjs
CHANGED
|
@@ -48,7 +48,6 @@ class RouterCore {
|
|
|
48
48
|
this.isScrollRestoring = false;
|
|
49
49
|
this.isScrollRestorationSetup = false;
|
|
50
50
|
this.startTransition = (fn) => fn();
|
|
51
|
-
this.isShell = false;
|
|
52
51
|
this.update = (newOptions) => {
|
|
53
52
|
var _a;
|
|
54
53
|
if (newOptions.notFoundRoute) {
|
|
@@ -75,7 +74,10 @@ class RouterCore {
|
|
|
75
74
|
this.basepath = `/${path.trimPath(newOptions.basepath)}`;
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
|
-
if (
|
|
77
|
+
if (
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
79
|
+
!this.history || this.options.history && this.options.history !== this.history
|
|
80
|
+
) {
|
|
79
81
|
this.history = this.options.history ?? (this.isServer ? history.createMemoryHistory({
|
|
80
82
|
initialEntries: [this.basepath || "/"]
|
|
81
83
|
}) : history.createBrowserHistory());
|
|
@@ -98,28 +100,16 @@ class RouterCore {
|
|
|
98
100
|
});
|
|
99
101
|
scrollRestoration.setupScrollRestoration(this);
|
|
100
102
|
}
|
|
101
|
-
if (typeof window !== "undefined" && "CSS" in window &&
|
|
103
|
+
if (typeof window !== "undefined" && "CSS" in window && // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
104
|
+
typeof ((_a = window.CSS) == null ? void 0 : _a.supports) === "function") {
|
|
102
105
|
this.isViewTransitionTypesSupported = window.CSS.supports(
|
|
103
106
|
"selector(:active-view-transition-type(a)"
|
|
104
107
|
);
|
|
105
108
|
}
|
|
106
|
-
if (this.latestLocation.search.__TSS_SHELL) {
|
|
107
|
-
this.isShell = true;
|
|
108
|
-
}
|
|
109
109
|
};
|
|
110
110
|
this.buildRouteTree = () => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
initRoute: (route, i) => {
|
|
114
|
-
route.init({
|
|
115
|
-
originalIndex: i,
|
|
116
|
-
defaultSsr: this.options.defaultSsr
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
this.routesById = routesById;
|
|
121
|
-
this.routesByPath = routesByPath;
|
|
122
|
-
this.flatRoutes = flatRoutes;
|
|
111
|
+
this.routesById = {};
|
|
112
|
+
this.routesByPath = {};
|
|
123
113
|
const notFoundRoute = this.options.notFoundRoute;
|
|
124
114
|
if (notFoundRoute) {
|
|
125
115
|
notFoundRoute.init({
|
|
@@ -128,6 +118,77 @@ class RouterCore {
|
|
|
128
118
|
});
|
|
129
119
|
this.routesById[notFoundRoute.id] = notFoundRoute;
|
|
130
120
|
}
|
|
121
|
+
const recurseRoutes = (childRoutes) => {
|
|
122
|
+
childRoutes.forEach((childRoute, i) => {
|
|
123
|
+
childRoute.init({
|
|
124
|
+
originalIndex: i,
|
|
125
|
+
defaultSsr: this.options.defaultSsr
|
|
126
|
+
});
|
|
127
|
+
const existingRoute = this.routesById[childRoute.id];
|
|
128
|
+
invariant(
|
|
129
|
+
!existingRoute,
|
|
130
|
+
`Duplicate routes found with id: ${String(childRoute.id)}`
|
|
131
|
+
);
|
|
132
|
+
this.routesById[childRoute.id] = childRoute;
|
|
133
|
+
if (!childRoute.isRoot && childRoute.path) {
|
|
134
|
+
const trimmedFullPath = path.trimPathRight(childRoute.fullPath);
|
|
135
|
+
if (!this.routesByPath[trimmedFullPath] || childRoute.fullPath.endsWith("/")) {
|
|
136
|
+
this.routesByPath[trimmedFullPath] = childRoute;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const children = childRoute.children;
|
|
140
|
+
if (children == null ? void 0 : children.length) {
|
|
141
|
+
recurseRoutes(children);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
recurseRoutes([this.routeTree]);
|
|
146
|
+
const scoredRoutes = [];
|
|
147
|
+
const routes = Object.values(this.routesById);
|
|
148
|
+
routes.forEach((d, i) => {
|
|
149
|
+
var _a;
|
|
150
|
+
if (d.isRoot || !d.path) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const trimmed = path.trimPathLeft(d.fullPath);
|
|
154
|
+
const parsed = path.parsePathname(trimmed);
|
|
155
|
+
while (parsed.length > 1 && ((_a = parsed[0]) == null ? void 0 : _a.value) === "/") {
|
|
156
|
+
parsed.shift();
|
|
157
|
+
}
|
|
158
|
+
const scores = parsed.map((segment) => {
|
|
159
|
+
if (segment.value === "/") {
|
|
160
|
+
return 0.75;
|
|
161
|
+
}
|
|
162
|
+
if (segment.type === "param") {
|
|
163
|
+
return 0.5;
|
|
164
|
+
}
|
|
165
|
+
if (segment.type === "wildcard") {
|
|
166
|
+
return 0.25;
|
|
167
|
+
}
|
|
168
|
+
return 1;
|
|
169
|
+
});
|
|
170
|
+
scoredRoutes.push({ child: d, trimmed, parsed, index: i, scores });
|
|
171
|
+
});
|
|
172
|
+
this.flatRoutes = scoredRoutes.sort((a, b) => {
|
|
173
|
+
const minLength = Math.min(a.scores.length, b.scores.length);
|
|
174
|
+
for (let i = 0; i < minLength; i++) {
|
|
175
|
+
if (a.scores[i] !== b.scores[i]) {
|
|
176
|
+
return b.scores[i] - a.scores[i];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (a.scores.length !== b.scores.length) {
|
|
180
|
+
return b.scores.length - a.scores.length;
|
|
181
|
+
}
|
|
182
|
+
for (let i = 0; i < minLength; i++) {
|
|
183
|
+
if (a.parsed[i].value !== b.parsed[i].value) {
|
|
184
|
+
return a.parsed[i].value > b.parsed[i].value ? 1 : -1;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return a.index - b.index;
|
|
188
|
+
}).map((d, i) => {
|
|
189
|
+
d.child.rank = i;
|
|
190
|
+
return d.child;
|
|
191
|
+
});
|
|
131
192
|
};
|
|
132
193
|
this.subscribe = (eventType, fn) => {
|
|
133
194
|
const listener = {
|
|
@@ -200,16 +261,37 @@ class RouterCore {
|
|
|
200
261
|
return this.matchRoutesInternal(pathnameOrNext, locationSearchOrOpts);
|
|
201
262
|
}
|
|
202
263
|
};
|
|
203
|
-
this.getMatchedRoutes = (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
264
|
+
this.getMatchedRoutes = (next, dest) => {
|
|
265
|
+
let routeParams = {};
|
|
266
|
+
const trimmedPath = path.trimPathRight(next.pathname);
|
|
267
|
+
const getMatchedParams = (route) => {
|
|
268
|
+
const result = path.matchPathname(this.basepath, trimmedPath, {
|
|
269
|
+
to: route.fullPath,
|
|
270
|
+
caseSensitive: route.options.caseSensitive ?? this.options.caseSensitive,
|
|
271
|
+
fuzzy: true
|
|
272
|
+
});
|
|
273
|
+
return result;
|
|
274
|
+
};
|
|
275
|
+
let foundRoute = (dest == null ? void 0 : dest.to) !== void 0 ? this.routesByPath[dest.to] : void 0;
|
|
276
|
+
if (foundRoute) {
|
|
277
|
+
routeParams = getMatchedParams(foundRoute);
|
|
278
|
+
} else {
|
|
279
|
+
foundRoute = this.flatRoutes.find((route) => {
|
|
280
|
+
const matchedParams = getMatchedParams(route);
|
|
281
|
+
if (matchedParams) {
|
|
282
|
+
routeParams = matchedParams;
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
return false;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
let routeCursor = foundRoute || this.routesById[root.rootRouteId];
|
|
289
|
+
const matchedRoutes = [routeCursor];
|
|
290
|
+
while (routeCursor.parentRoute) {
|
|
291
|
+
routeCursor = routeCursor.parentRoute;
|
|
292
|
+
matchedRoutes.unshift(routeCursor);
|
|
293
|
+
}
|
|
294
|
+
return { matchedRoutes, routeParams, foundRoute };
|
|
213
295
|
};
|
|
214
296
|
this.cancelMatch = (id) => {
|
|
215
297
|
const match = this.getMatch(id);
|
|
@@ -422,16 +504,10 @@ class RouterCore {
|
|
|
422
504
|
maskedNext = build(maskedDest);
|
|
423
505
|
}
|
|
424
506
|
}
|
|
425
|
-
const nextMatches = this.getMatchedRoutes(
|
|
426
|
-
next.pathname,
|
|
427
|
-
dest.to
|
|
428
|
-
);
|
|
507
|
+
const nextMatches = this.getMatchedRoutes(next, dest);
|
|
429
508
|
const final = build(dest, nextMatches);
|
|
430
509
|
if (maskedNext) {
|
|
431
|
-
const maskedMatches = this.getMatchedRoutes(
|
|
432
|
-
maskedNext.pathname,
|
|
433
|
-
maskedDest == null ? void 0 : maskedDest.to
|
|
434
|
-
);
|
|
510
|
+
const maskedMatches = this.getMatchedRoutes(maskedNext, maskedDest);
|
|
435
511
|
const maskedFinal = build(maskedDest, maskedMatches);
|
|
436
512
|
final.maskedLocation = maskedFinal;
|
|
437
513
|
}
|
|
@@ -542,13 +618,6 @@ class RouterCore {
|
|
|
542
618
|
});
|
|
543
619
|
};
|
|
544
620
|
this.navigate = ({ to, reloadDocument, href, ...rest }) => {
|
|
545
|
-
if (!reloadDocument && href) {
|
|
546
|
-
try {
|
|
547
|
-
new URL(`${href}`);
|
|
548
|
-
reloadDocument = true;
|
|
549
|
-
} catch {
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
621
|
if (reloadDocument) {
|
|
553
622
|
if (!href) {
|
|
554
623
|
const location = this.buildLocation({ to, ...rest });
|
|
@@ -567,23 +636,8 @@ class RouterCore {
|
|
|
567
636
|
to
|
|
568
637
|
});
|
|
569
638
|
};
|
|
570
|
-
this.beforeLoad = () => {
|
|
571
|
-
this.cancelMatches();
|
|
572
|
-
this.latestLocation = this.parseLocation(this.latestLocation);
|
|
573
|
-
const pendingMatches = this.matchRoutes(this.latestLocation);
|
|
574
|
-
this.__store.setState((s) => ({
|
|
575
|
-
...s,
|
|
576
|
-
status: "pending",
|
|
577
|
-
isLoading: true,
|
|
578
|
-
location: this.latestLocation,
|
|
579
|
-
pendingMatches,
|
|
580
|
-
// If a cached moved to pendingMatches, remove it from cachedMatches
|
|
581
|
-
cachedMatches: s.cachedMatches.filter((d) => {
|
|
582
|
-
return !pendingMatches.find((e) => e.id === d.id);
|
|
583
|
-
})
|
|
584
|
-
}));
|
|
585
|
-
};
|
|
586
639
|
this.load = async (opts) => {
|
|
640
|
+
this.latestLocation = this.parseLocation(this.latestLocation);
|
|
587
641
|
let redirect$1;
|
|
588
642
|
let notFound$1;
|
|
589
643
|
let loadPromise;
|
|
@@ -591,9 +645,24 @@ class RouterCore {
|
|
|
591
645
|
this.startTransition(async () => {
|
|
592
646
|
var _a;
|
|
593
647
|
try {
|
|
594
|
-
this.beforeLoad();
|
|
595
648
|
const next = this.latestLocation;
|
|
596
649
|
const prevLocation = this.state.resolvedLocation;
|
|
650
|
+
this.cancelMatches();
|
|
651
|
+
let pendingMatches;
|
|
652
|
+
store.batch(() => {
|
|
653
|
+
pendingMatches = this.matchRoutes(next);
|
|
654
|
+
this.__store.setState((s) => ({
|
|
655
|
+
...s,
|
|
656
|
+
status: "pending",
|
|
657
|
+
isLoading: true,
|
|
658
|
+
location: next,
|
|
659
|
+
pendingMatches,
|
|
660
|
+
// If a cached moved to pendingMatches, remove it from cachedMatches
|
|
661
|
+
cachedMatches: s.cachedMatches.filter((d) => {
|
|
662
|
+
return !pendingMatches.find((e) => e.id === d.id);
|
|
663
|
+
})
|
|
664
|
+
}));
|
|
665
|
+
});
|
|
597
666
|
if (!this.state.redirect) {
|
|
598
667
|
this.emit({
|
|
599
668
|
type: "onBeforeNavigate",
|
|
@@ -612,7 +681,7 @@ class RouterCore {
|
|
|
612
681
|
});
|
|
613
682
|
await this.loadMatches({
|
|
614
683
|
sync: opts == null ? void 0 : opts.sync,
|
|
615
|
-
matches:
|
|
684
|
+
matches: pendingMatches,
|
|
616
685
|
location: next,
|
|
617
686
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
618
687
|
onReady: async () => {
|
|
@@ -661,11 +730,11 @@ class RouterCore {
|
|
|
661
730
|
}
|
|
662
731
|
});
|
|
663
732
|
} catch (err) {
|
|
664
|
-
if (redirect.
|
|
733
|
+
if (redirect.isResolvedRedirect(err)) {
|
|
665
734
|
redirect$1 = err;
|
|
666
735
|
if (!this.isServer) {
|
|
667
736
|
this.navigate({
|
|
668
|
-
...redirect$1
|
|
737
|
+
...redirect$1,
|
|
669
738
|
replace: true,
|
|
670
739
|
ignoreBlocker: true
|
|
671
740
|
});
|
|
@@ -675,7 +744,7 @@ class RouterCore {
|
|
|
675
744
|
}
|
|
676
745
|
this.__store.setState((s) => ({
|
|
677
746
|
...s,
|
|
678
|
-
statusCode: redirect$1 ? redirect$1.
|
|
747
|
+
statusCode: redirect$1 ? redirect$1.statusCode : notFound$1 ? 404 : s.matches.some((d) => d.status === "error") ? 500 : 200,
|
|
679
748
|
redirect: redirect$1
|
|
680
749
|
}));
|
|
681
750
|
}
|
|
@@ -773,14 +842,12 @@ class RouterCore {
|
|
|
773
842
|
};
|
|
774
843
|
const handleRedirectAndNotFound = (match, err) => {
|
|
775
844
|
var _a, _b, _c, _d;
|
|
776
|
-
if (redirect.
|
|
777
|
-
if (
|
|
778
|
-
|
|
779
|
-
if (!err.options.reloadDocument) {
|
|
780
|
-
throw err;
|
|
781
|
-
}
|
|
782
|
-
}
|
|
845
|
+
if (redirect.isResolvedRedirect(err)) {
|
|
846
|
+
if (!err.reloadDocument) {
|
|
847
|
+
throw err;
|
|
783
848
|
}
|
|
849
|
+
}
|
|
850
|
+
if (redirect.isRedirect(err) || notFound.isNotFound(err)) {
|
|
784
851
|
updateMatch(match.id, (prev) => ({
|
|
785
852
|
...prev,
|
|
786
853
|
status: redirect.isRedirect(err) ? "redirected" : notFound.isNotFound(err) ? "notFound" : "error",
|
|
@@ -797,9 +864,7 @@ class RouterCore {
|
|
|
797
864
|
(_c = match.loadPromise) == null ? void 0 : _c.resolve();
|
|
798
865
|
if (redirect.isRedirect(err)) {
|
|
799
866
|
rendered = true;
|
|
800
|
-
err.
|
|
801
|
-
err.redirectHandled = true;
|
|
802
|
-
err = this.resolveRedirect(err);
|
|
867
|
+
err = this.resolveRedirect({ ...err, _fromLocation: location });
|
|
803
868
|
throw err;
|
|
804
869
|
} else if (notFound.isNotFound(err)) {
|
|
805
870
|
this._handleNotFound(matches, err, {
|
|
@@ -1105,8 +1170,8 @@ class RouterCore {
|
|
|
1105
1170
|
loaderPromise: void 0
|
|
1106
1171
|
}));
|
|
1107
1172
|
} catch (err) {
|
|
1108
|
-
if (redirect.
|
|
1109
|
-
await this.navigate(err
|
|
1173
|
+
if (redirect.isResolvedRedirect(err)) {
|
|
1174
|
+
await this.navigate(err);
|
|
1110
1175
|
}
|
|
1111
1176
|
}
|
|
1112
1177
|
})();
|
|
@@ -1170,13 +1235,10 @@ class RouterCore {
|
|
|
1170
1235
|
});
|
|
1171
1236
|
return this.load({ sync: opts == null ? void 0 : opts.sync });
|
|
1172
1237
|
};
|
|
1173
|
-
this.resolveRedirect = (
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
redirect2.
|
|
1177
|
-
}
|
|
1178
|
-
if (!redirect2.headers.get("Location")) {
|
|
1179
|
-
redirect2.headers.set("Location", redirect2.options.href);
|
|
1238
|
+
this.resolveRedirect = (err) => {
|
|
1239
|
+
const redirect2 = err;
|
|
1240
|
+
if (!redirect2.href) {
|
|
1241
|
+
redirect2.href = this.buildLocation(redirect2).href;
|
|
1180
1242
|
}
|
|
1181
1243
|
return redirect2;
|
|
1182
1244
|
};
|
|
@@ -1278,11 +1340,11 @@ class RouterCore {
|
|
|
1278
1340
|
return matches;
|
|
1279
1341
|
} catch (err) {
|
|
1280
1342
|
if (redirect.isRedirect(err)) {
|
|
1281
|
-
if (err.
|
|
1343
|
+
if (err.reloadDocument) {
|
|
1282
1344
|
return void 0;
|
|
1283
1345
|
}
|
|
1284
1346
|
return await this.preloadRoute({
|
|
1285
|
-
...err
|
|
1347
|
+
...err,
|
|
1286
1348
|
_fromLocation: next
|
|
1287
1349
|
});
|
|
1288
1350
|
}
|
|
@@ -1386,10 +1448,9 @@ class RouterCore {
|
|
|
1386
1448
|
return this.routesById;
|
|
1387
1449
|
}
|
|
1388
1450
|
matchRoutesInternal(next, opts) {
|
|
1389
|
-
var _a;
|
|
1390
1451
|
const { foundRoute, matchedRoutes, routeParams } = this.getMatchedRoutes(
|
|
1391
|
-
next
|
|
1392
|
-
|
|
1452
|
+
next,
|
|
1453
|
+
opts == null ? void 0 : opts.dest
|
|
1393
1454
|
);
|
|
1394
1455
|
let isGlobalNotFound = false;
|
|
1395
1456
|
if (
|
|
@@ -1420,9 +1481,9 @@ class RouterCore {
|
|
|
1420
1481
|
return root.rootRouteId;
|
|
1421
1482
|
})();
|
|
1422
1483
|
const parseErrors = matchedRoutes.map((route) => {
|
|
1423
|
-
var
|
|
1484
|
+
var _a;
|
|
1424
1485
|
let parsedParamsError;
|
|
1425
|
-
const parseParams = ((
|
|
1486
|
+
const parseParams = ((_a = route.options.params) == null ? void 0 : _a.parse) ?? route.options.parseParams;
|
|
1426
1487
|
if (parseParams) {
|
|
1427
1488
|
try {
|
|
1428
1489
|
const parsedParams = parseParams(routeParams);
|
|
@@ -1446,7 +1507,7 @@ class RouterCore {
|
|
|
1446
1507
|
return parentContext;
|
|
1447
1508
|
};
|
|
1448
1509
|
matchedRoutes.forEach((route, index) => {
|
|
1449
|
-
var
|
|
1510
|
+
var _a, _b;
|
|
1450
1511
|
const parentMatch = matches[index - 1];
|
|
1451
1512
|
const [preMatchSearch, strictMatchSearch, searchError] = (() => {
|
|
1452
1513
|
const parentSearch = (parentMatch == null ? void 0 : parentMatch.search) ?? next.search;
|
|
@@ -1474,7 +1535,7 @@ class RouterCore {
|
|
|
1474
1535
|
return [parentSearch, {}, searchParamError];
|
|
1475
1536
|
}
|
|
1476
1537
|
})();
|
|
1477
|
-
const loaderDeps = ((_b = (
|
|
1538
|
+
const loaderDeps = ((_b = (_a = route.options).loaderDeps) == null ? void 0 : _b.call(_a, {
|
|
1478
1539
|
search: preMatchSearch
|
|
1479
1540
|
})) ?? "";
|
|
1480
1541
|
const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : "";
|
|
@@ -1552,7 +1613,7 @@ class RouterCore {
|
|
|
1552
1613
|
matches.push(match);
|
|
1553
1614
|
});
|
|
1554
1615
|
matches.forEach((match, index) => {
|
|
1555
|
-
var
|
|
1616
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1556
1617
|
const route = this.looseRoutesById[match.routeId];
|
|
1557
1618
|
const existingMatch = this.getMatch(match.id);
|
|
1558
1619
|
if (!existingMatch && (opts == null ? void 0 : opts._buildLocation) !== true) {
|
|
@@ -1570,7 +1631,7 @@ class RouterCore {
|
|
|
1570
1631
|
preload: !!match.preload,
|
|
1571
1632
|
matches
|
|
1572
1633
|
};
|
|
1573
|
-
match.__routeContext = ((_b = (
|
|
1634
|
+
match.__routeContext = ((_b = (_a = route.options).context) == null ? void 0 : _b.call(_a, contextFnContext)) ?? {};
|
|
1574
1635
|
match.context = {
|
|
1575
1636
|
...parentContext,
|
|
1576
1637
|
...match.__routeContext,
|
|
@@ -1656,141 +1717,6 @@ function routeNeedsPreload(route) {
|
|
|
1656
1717
|
}
|
|
1657
1718
|
return false;
|
|
1658
1719
|
}
|
|
1659
|
-
function processRouteTree({
|
|
1660
|
-
routeTree,
|
|
1661
|
-
initRoute
|
|
1662
|
-
}) {
|
|
1663
|
-
const routesById = {};
|
|
1664
|
-
const routesByPath = {};
|
|
1665
|
-
const recurseRoutes = (childRoutes) => {
|
|
1666
|
-
childRoutes.forEach((childRoute, i) => {
|
|
1667
|
-
initRoute == null ? void 0 : initRoute(childRoute, i);
|
|
1668
|
-
const existingRoute = routesById[childRoute.id];
|
|
1669
|
-
invariant(
|
|
1670
|
-
!existingRoute,
|
|
1671
|
-
`Duplicate routes found with id: ${String(childRoute.id)}`
|
|
1672
|
-
);
|
|
1673
|
-
routesById[childRoute.id] = childRoute;
|
|
1674
|
-
if (!childRoute.isRoot && childRoute.path) {
|
|
1675
|
-
const trimmedFullPath = path.trimPathRight(childRoute.fullPath);
|
|
1676
|
-
if (!routesByPath[trimmedFullPath] || childRoute.fullPath.endsWith("/")) {
|
|
1677
|
-
routesByPath[trimmedFullPath] = childRoute;
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
const children = childRoute.children;
|
|
1681
|
-
if (children == null ? void 0 : children.length) {
|
|
1682
|
-
recurseRoutes(children);
|
|
1683
|
-
}
|
|
1684
|
-
});
|
|
1685
|
-
};
|
|
1686
|
-
recurseRoutes([routeTree]);
|
|
1687
|
-
const scoredRoutes = [];
|
|
1688
|
-
const routes = Object.values(routesById);
|
|
1689
|
-
routes.forEach((d, i) => {
|
|
1690
|
-
var _a;
|
|
1691
|
-
if (d.isRoot || !d.path) {
|
|
1692
|
-
return;
|
|
1693
|
-
}
|
|
1694
|
-
const trimmed = path.trimPathLeft(d.fullPath);
|
|
1695
|
-
const parsed = path.parsePathname(trimmed);
|
|
1696
|
-
while (parsed.length > 1 && ((_a = parsed[0]) == null ? void 0 : _a.value) === "/") {
|
|
1697
|
-
parsed.shift();
|
|
1698
|
-
}
|
|
1699
|
-
const scores = parsed.map((segment) => {
|
|
1700
|
-
if (segment.value === "/") {
|
|
1701
|
-
return 0.75;
|
|
1702
|
-
}
|
|
1703
|
-
if (segment.type === "param" && segment.prefixSegment && segment.suffixSegment) {
|
|
1704
|
-
return 0.55;
|
|
1705
|
-
}
|
|
1706
|
-
if (segment.type === "param" && segment.prefixSegment) {
|
|
1707
|
-
return 0.52;
|
|
1708
|
-
}
|
|
1709
|
-
if (segment.type === "param" && segment.suffixSegment) {
|
|
1710
|
-
return 0.51;
|
|
1711
|
-
}
|
|
1712
|
-
if (segment.type === "param") {
|
|
1713
|
-
return 0.5;
|
|
1714
|
-
}
|
|
1715
|
-
if (segment.type === "wildcard" && segment.prefixSegment && segment.suffixSegment) {
|
|
1716
|
-
return 0.3;
|
|
1717
|
-
}
|
|
1718
|
-
if (segment.type === "wildcard" && segment.prefixSegment) {
|
|
1719
|
-
return 0.27;
|
|
1720
|
-
}
|
|
1721
|
-
if (segment.type === "wildcard" && segment.suffixSegment) {
|
|
1722
|
-
return 0.26;
|
|
1723
|
-
}
|
|
1724
|
-
if (segment.type === "wildcard") {
|
|
1725
|
-
return 0.25;
|
|
1726
|
-
}
|
|
1727
|
-
return 1;
|
|
1728
|
-
});
|
|
1729
|
-
scoredRoutes.push({ child: d, trimmed, parsed, index: i, scores });
|
|
1730
|
-
});
|
|
1731
|
-
const flatRoutes = scoredRoutes.sort((a, b) => {
|
|
1732
|
-
const minLength = Math.min(a.scores.length, b.scores.length);
|
|
1733
|
-
for (let i = 0; i < minLength; i++) {
|
|
1734
|
-
if (a.scores[i] !== b.scores[i]) {
|
|
1735
|
-
return b.scores[i] - a.scores[i];
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
if (a.scores.length !== b.scores.length) {
|
|
1739
|
-
return b.scores.length - a.scores.length;
|
|
1740
|
-
}
|
|
1741
|
-
for (let i = 0; i < minLength; i++) {
|
|
1742
|
-
if (a.parsed[i].value !== b.parsed[i].value) {
|
|
1743
|
-
return a.parsed[i].value > b.parsed[i].value ? 1 : -1;
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
return a.index - b.index;
|
|
1747
|
-
}).map((d, i) => {
|
|
1748
|
-
d.child.rank = i;
|
|
1749
|
-
return d.child;
|
|
1750
|
-
});
|
|
1751
|
-
return { routesById, routesByPath, flatRoutes };
|
|
1752
|
-
}
|
|
1753
|
-
function getMatchedRoutes({
|
|
1754
|
-
pathname,
|
|
1755
|
-
routePathname,
|
|
1756
|
-
basepath,
|
|
1757
|
-
caseSensitive,
|
|
1758
|
-
routesByPath,
|
|
1759
|
-
routesById,
|
|
1760
|
-
flatRoutes
|
|
1761
|
-
}) {
|
|
1762
|
-
let routeParams = {};
|
|
1763
|
-
const trimmedPath = path.trimPathRight(pathname);
|
|
1764
|
-
const getMatchedParams = (route) => {
|
|
1765
|
-
var _a;
|
|
1766
|
-
const result = path.matchPathname(basepath, trimmedPath, {
|
|
1767
|
-
to: route.fullPath,
|
|
1768
|
-
caseSensitive: ((_a = route.options) == null ? void 0 : _a.caseSensitive) ?? caseSensitive,
|
|
1769
|
-
fuzzy: true
|
|
1770
|
-
});
|
|
1771
|
-
return result;
|
|
1772
|
-
};
|
|
1773
|
-
let foundRoute = routePathname !== void 0 ? routesByPath[routePathname] : void 0;
|
|
1774
|
-
if (foundRoute) {
|
|
1775
|
-
routeParams = getMatchedParams(foundRoute);
|
|
1776
|
-
} else {
|
|
1777
|
-
foundRoute = flatRoutes.find((route) => {
|
|
1778
|
-
const matchedParams = getMatchedParams(route);
|
|
1779
|
-
if (matchedParams) {
|
|
1780
|
-
routeParams = matchedParams;
|
|
1781
|
-
return true;
|
|
1782
|
-
}
|
|
1783
|
-
return false;
|
|
1784
|
-
});
|
|
1785
|
-
}
|
|
1786
|
-
let routeCursor = foundRoute || routesById[root.rootRouteId];
|
|
1787
|
-
const matchedRoutes = [routeCursor];
|
|
1788
|
-
while (routeCursor.parentRoute) {
|
|
1789
|
-
routeCursor = routeCursor.parentRoute;
|
|
1790
|
-
matchedRoutes.unshift(routeCursor);
|
|
1791
|
-
}
|
|
1792
|
-
return { matchedRoutes, routeParams, foundRoute };
|
|
1793
|
-
}
|
|
1794
1720
|
exports.PathParamError = PathParamError;
|
|
1795
1721
|
exports.RouterCore = RouterCore;
|
|
1796
1722
|
exports.SearchParamError = SearchParamError;
|
|
@@ -1798,7 +1724,5 @@ exports.componentTypes = componentTypes;
|
|
|
1798
1724
|
exports.defaultSerializeError = defaultSerializeError;
|
|
1799
1725
|
exports.getInitialRouterState = getInitialRouterState;
|
|
1800
1726
|
exports.getLocationChangeInfo = getLocationChangeInfo;
|
|
1801
|
-
exports.getMatchedRoutes = getMatchedRoutes;
|
|
1802
1727
|
exports.lazyFn = lazyFn;
|
|
1803
|
-
exports.processRouteTree = processRouteTree;
|
|
1804
1728
|
//# sourceMappingURL=router.cjs.map
|