@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.
Files changed (58) hide show
  1. package/dist/cjs/fileRoute.d.cts +2 -6
  2. package/dist/cjs/index.cjs +0 -3
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/index.d.cts +6 -6
  5. package/dist/cjs/link.cjs.map +1 -1
  6. package/dist/cjs/link.d.cts +1 -18
  7. package/dist/cjs/path.cjs +16 -130
  8. package/dist/cjs/path.cjs.map +1 -1
  9. package/dist/cjs/path.d.cts +0 -17
  10. package/dist/cjs/redirect.cjs +14 -17
  11. package/dist/cjs/redirect.cjs.map +1 -1
  12. package/dist/cjs/redirect.d.cts +7 -13
  13. package/dist/cjs/route.cjs +1 -12
  14. package/dist/cjs/route.cjs.map +1 -1
  15. package/dist/cjs/route.d.cts +16 -19
  16. package/dist/cjs/router.cjs +214 -287
  17. package/dist/cjs/router.cjs.map +1 -1
  18. package/dist/cjs/router.d.cts +3 -46
  19. package/dist/cjs/scroll-restoration.cjs +23 -12
  20. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  21. package/dist/cjs/scroll-restoration.d.cts +1 -1
  22. package/dist/cjs/typePrimitives.d.cts +2 -2
  23. package/dist/cjs/utils.cjs.map +1 -1
  24. package/dist/cjs/utils.d.cts +0 -2
  25. package/dist/esm/fileRoute.d.ts +2 -6
  26. package/dist/esm/index.d.ts +6 -6
  27. package/dist/esm/index.js +2 -5
  28. package/dist/esm/link.d.ts +1 -18
  29. package/dist/esm/link.js.map +1 -1
  30. package/dist/esm/path.d.ts +0 -17
  31. package/dist/esm/path.js +16 -130
  32. package/dist/esm/path.js.map +1 -1
  33. package/dist/esm/redirect.d.ts +7 -13
  34. package/dist/esm/redirect.js +14 -17
  35. package/dist/esm/redirect.js.map +1 -1
  36. package/dist/esm/route.d.ts +16 -19
  37. package/dist/esm/route.js +1 -12
  38. package/dist/esm/route.js.map +1 -1
  39. package/dist/esm/router.d.ts +3 -46
  40. package/dist/esm/router.js +217 -290
  41. package/dist/esm/router.js.map +1 -1
  42. package/dist/esm/scroll-restoration.d.ts +1 -1
  43. package/dist/esm/scroll-restoration.js +23 -12
  44. package/dist/esm/scroll-restoration.js.map +1 -1
  45. package/dist/esm/typePrimitives.d.ts +2 -2
  46. package/dist/esm/utils.d.ts +0 -2
  47. package/dist/esm/utils.js.map +1 -1
  48. package/package.json +2 -2
  49. package/src/fileRoute.ts +1 -90
  50. package/src/index.ts +6 -14
  51. package/src/link.ts +11 -97
  52. package/src/path.ts +16 -181
  53. package/src/redirect.ts +22 -37
  54. package/src/route.ts +50 -108
  55. package/src/router.ts +270 -392
  56. package/src/scroll-restoration.ts +44 -27
  57. package/src/typePrimitives.ts +2 -2
  58. package/src/utils.ts +0 -14
@@ -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 (!this.history || this.options.history && this.options.history !== this.history) {
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 && typeof ((_a = window.CSS) == null ? void 0 : _a.supports) === "function") {
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
- const { routesById, routesByPath, flatRoutes } = processRouteTree({
112
- routeTree: this.routeTree,
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 = (pathname, routePathname) => {
204
- return getMatchedRoutes({
205
- pathname,
206
- routePathname,
207
- basepath: this.basepath,
208
- caseSensitive: this.options.caseSensitive,
209
- routesByPath: this.routesByPath,
210
- routesById: this.routesById,
211
- flatRoutes: this.flatRoutes
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: this.state.pendingMatches,
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.isRedirect(err)) {
733
+ if (redirect.isResolvedRedirect(err)) {
665
734
  redirect$1 = err;
666
735
  if (!this.isServer) {
667
736
  this.navigate({
668
- ...redirect$1.options,
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.status : notFound$1 ? 404 : s.matches.some((d) => d.status === "error") ? 500 : 200,
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.isRedirect(err) || notFound.isNotFound(err)) {
777
- if (redirect.isRedirect(err)) {
778
- if (err.redirectHandled) {
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.options._fromLocation = location;
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, {
@@ -1007,8 +1072,35 @@ class RouterCore {
1007
1072
  loaderPromise: utils.createControlledPromise(),
1008
1073
  preload: !!preload && !this.state.matches.find((d) => d.id === matchId)
1009
1074
  }));
1075
+ const executeHead = () => {
1076
+ var _a2, _b2, _c2, _d2, _e, _f;
1077
+ const match = this.getMatch(matchId);
1078
+ if (!match) {
1079
+ return;
1080
+ }
1081
+ const assetContext = {
1082
+ matches,
1083
+ match,
1084
+ params: match.params,
1085
+ loaderData: match.loaderData
1086
+ };
1087
+ const headFnContent = (_b2 = (_a2 = route.options).head) == null ? void 0 : _b2.call(_a2, assetContext);
1088
+ const meta = headFnContent == null ? void 0 : headFnContent.meta;
1089
+ const links = headFnContent == null ? void 0 : headFnContent.links;
1090
+ const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
1091
+ const scripts = (_d2 = (_c2 = route.options).scripts) == null ? void 0 : _d2.call(_c2, assetContext);
1092
+ const headers = (_f = (_e = route.options).headers) == null ? void 0 : _f.call(_e, assetContext);
1093
+ updateMatch(matchId, (prev) => ({
1094
+ ...prev,
1095
+ meta,
1096
+ links,
1097
+ headScripts,
1098
+ headers,
1099
+ scripts
1100
+ }));
1101
+ };
1010
1102
  const runLoader = async () => {
1011
- var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k;
1103
+ var _a2, _b2, _c2, _d2, _e;
1012
1104
  try {
1013
1105
  const potentialPendingMinPromise = async () => {
1014
1106
  const latestMatch = this.getMatch(matchId);
@@ -1029,40 +1121,24 @@ class RouterCore {
1029
1121
  );
1030
1122
  await route._lazyPromise;
1031
1123
  await potentialPendingMinPromise();
1032
- const assetContext = {
1033
- matches,
1034
- match: this.getMatch(matchId),
1035
- params: this.getMatch(matchId).params,
1036
- loaderData
1037
- };
1038
- const headFnContent = (_d2 = (_c2 = route.options).head) == null ? void 0 : _d2.call(_c2, assetContext);
1039
- const meta = headFnContent == null ? void 0 : headFnContent.meta;
1040
- const links = headFnContent == null ? void 0 : headFnContent.links;
1041
- const headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
1042
- const scripts = (_f = (_e = route.options).scripts) == null ? void 0 : _f.call(_e, assetContext);
1043
- const headers = (_h = (_g = route.options).headers) == null ? void 0 : _h.call(_g, {
1044
- loaderData
1045
- });
1046
1124
  await route._componentsPromise;
1047
- updateMatch(matchId, (prev) => ({
1048
- ...prev,
1049
- error: void 0,
1050
- status: "success",
1051
- isFetching: false,
1052
- updatedAt: Date.now(),
1053
- loaderData,
1054
- meta,
1055
- links,
1056
- headScripts,
1057
- headers,
1058
- scripts
1059
- }));
1125
+ store.batch(() => {
1126
+ updateMatch(matchId, (prev) => ({
1127
+ ...prev,
1128
+ error: void 0,
1129
+ status: "success",
1130
+ isFetching: false,
1131
+ updatedAt: Date.now(),
1132
+ loaderData
1133
+ }));
1134
+ executeHead();
1135
+ });
1060
1136
  } catch (e) {
1061
1137
  let error = e;
1062
1138
  await potentialPendingMinPromise();
1063
1139
  handleRedirectAndNotFound(this.getMatch(matchId), e);
1064
1140
  try {
1065
- (_j = (_i = route.options).onError) == null ? void 0 : _j.call(_i, e);
1141
+ (_d2 = (_c2 = route.options).onError) == null ? void 0 : _d2.call(_c2, e);
1066
1142
  } catch (onErrorError) {
1067
1143
  error = onErrorError;
1068
1144
  handleRedirectAndNotFound(
@@ -1070,22 +1146,28 @@ class RouterCore {
1070
1146
  onErrorError
1071
1147
  );
1072
1148
  }
1073
- updateMatch(matchId, (prev) => ({
1074
- ...prev,
1075
- error,
1076
- status: "error",
1077
- isFetching: false
1078
- }));
1149
+ store.batch(() => {
1150
+ updateMatch(matchId, (prev) => ({
1151
+ ...prev,
1152
+ error,
1153
+ status: "error",
1154
+ isFetching: false
1155
+ }));
1156
+ executeHead();
1157
+ });
1079
1158
  }
1080
- (_k = this.serverSsr) == null ? void 0 : _k.onMatchSettled({
1159
+ (_e = this.serverSsr) == null ? void 0 : _e.onMatchSettled({
1081
1160
  router: this,
1082
1161
  match: this.getMatch(matchId)
1083
1162
  });
1084
1163
  } catch (err) {
1085
- updateMatch(matchId, (prev) => ({
1086
- ...prev,
1087
- loaderPromise: void 0
1088
- }));
1164
+ store.batch(() => {
1165
+ updateMatch(matchId, (prev) => ({
1166
+ ...prev,
1167
+ loaderPromise: void 0
1168
+ }));
1169
+ executeHead();
1170
+ });
1089
1171
  handleRedirectAndNotFound(this.getMatch(matchId), err);
1090
1172
  }
1091
1173
  };
@@ -1105,13 +1187,15 @@ class RouterCore {
1105
1187
  loaderPromise: void 0
1106
1188
  }));
1107
1189
  } catch (err) {
1108
- if (redirect.isRedirect(err)) {
1109
- await this.navigate(err.options);
1190
+ if (redirect.isResolvedRedirect(err)) {
1191
+ await this.navigate(err);
1110
1192
  }
1111
1193
  }
1112
1194
  })();
1113
1195
  } else if (status !== "success" || loaderShouldRunAsync && sync) {
1114
1196
  await runLoader();
1197
+ } else {
1198
+ executeHead();
1115
1199
  }
1116
1200
  }
1117
1201
  if (!loaderIsRunningAsync) {
@@ -1170,13 +1254,10 @@ class RouterCore {
1170
1254
  });
1171
1255
  return this.load({ sync: opts == null ? void 0 : opts.sync });
1172
1256
  };
1173
- this.resolveRedirect = (redirect2) => {
1174
- if (!redirect2.options.href) {
1175
- redirect2.options.href = this.buildLocation(redirect2.options).href;
1176
- redirect2.headers.set("Location", redirect2.options.href);
1177
- }
1178
- if (!redirect2.headers.get("Location")) {
1179
- redirect2.headers.set("Location", redirect2.options.href);
1257
+ this.resolveRedirect = (err) => {
1258
+ const redirect2 = err;
1259
+ if (!redirect2.href) {
1260
+ redirect2.href = this.buildLocation(redirect2).href;
1180
1261
  }
1181
1262
  return redirect2;
1182
1263
  };
@@ -1278,11 +1359,11 @@ class RouterCore {
1278
1359
  return matches;
1279
1360
  } catch (err) {
1280
1361
  if (redirect.isRedirect(err)) {
1281
- if (err.options.reloadDocument) {
1362
+ if (err.reloadDocument) {
1282
1363
  return void 0;
1283
1364
  }
1284
1365
  return await this.preloadRoute({
1285
- ...err.options,
1366
+ ...err,
1286
1367
  _fromLocation: next
1287
1368
  });
1288
1369
  }
@@ -1386,10 +1467,9 @@ class RouterCore {
1386
1467
  return this.routesById;
1387
1468
  }
1388
1469
  matchRoutesInternal(next, opts) {
1389
- var _a;
1390
1470
  const { foundRoute, matchedRoutes, routeParams } = this.getMatchedRoutes(
1391
- next.pathname,
1392
- (_a = opts == null ? void 0 : opts.dest) == null ? void 0 : _a.to
1471
+ next,
1472
+ opts == null ? void 0 : opts.dest
1393
1473
  );
1394
1474
  let isGlobalNotFound = false;
1395
1475
  if (
@@ -1420,9 +1500,9 @@ class RouterCore {
1420
1500
  return root.rootRouteId;
1421
1501
  })();
1422
1502
  const parseErrors = matchedRoutes.map((route) => {
1423
- var _a2;
1503
+ var _a;
1424
1504
  let parsedParamsError;
1425
- const parseParams = ((_a2 = route.options.params) == null ? void 0 : _a2.parse) ?? route.options.parseParams;
1505
+ const parseParams = ((_a = route.options.params) == null ? void 0 : _a.parse) ?? route.options.parseParams;
1426
1506
  if (parseParams) {
1427
1507
  try {
1428
1508
  const parsedParams = parseParams(routeParams);
@@ -1446,7 +1526,7 @@ class RouterCore {
1446
1526
  return parentContext;
1447
1527
  };
1448
1528
  matchedRoutes.forEach((route, index) => {
1449
- var _a2, _b;
1529
+ var _a, _b;
1450
1530
  const parentMatch = matches[index - 1];
1451
1531
  const [preMatchSearch, strictMatchSearch, searchError] = (() => {
1452
1532
  const parentSearch = (parentMatch == null ? void 0 : parentMatch.search) ?? next.search;
@@ -1474,7 +1554,7 @@ class RouterCore {
1474
1554
  return [parentSearch, {}, searchParamError];
1475
1555
  }
1476
1556
  })();
1477
- const loaderDeps = ((_b = (_a2 = route.options).loaderDeps) == null ? void 0 : _b.call(_a2, {
1557
+ const loaderDeps = ((_b = (_a = route.options).loaderDeps) == null ? void 0 : _b.call(_a, {
1478
1558
  search: preMatchSearch
1479
1559
  })) ?? "";
1480
1560
  const loaderDepsHash = loaderDeps ? JSON.stringify(loaderDeps) : "";
@@ -1552,7 +1632,7 @@ class RouterCore {
1552
1632
  matches.push(match);
1553
1633
  });
1554
1634
  matches.forEach((match, index) => {
1555
- var _a2, _b, _c, _d, _e, _f, _g, _h;
1635
+ var _a, _b;
1556
1636
  const route = this.looseRoutesById[match.routeId];
1557
1637
  const existingMatch = this.getMatch(match.id);
1558
1638
  if (!existingMatch && (opts == null ? void 0 : opts._buildLocation) !== true) {
@@ -1570,29 +1650,13 @@ class RouterCore {
1570
1650
  preload: !!match.preload,
1571
1651
  matches
1572
1652
  };
1573
- match.__routeContext = ((_b = (_a2 = route.options).context) == null ? void 0 : _b.call(_a2, contextFnContext)) ?? {};
1653
+ match.__routeContext = ((_b = (_a = route.options).context) == null ? void 0 : _b.call(_a, contextFnContext)) ?? {};
1574
1654
  match.context = {
1575
1655
  ...parentContext,
1576
1656
  ...match.__routeContext,
1577
1657
  ...match.__beforeLoadContext
1578
1658
  };
1579
1659
  }
1580
- if (match.status === "success") {
1581
- match.headers = (_d = (_c = route.options).headers) == null ? void 0 : _d.call(_c, {
1582
- loaderData: match.loaderData
1583
- });
1584
- const assetContext = {
1585
- matches,
1586
- match,
1587
- params: match.params,
1588
- loaderData: match.loaderData
1589
- };
1590
- const headFnContent = (_f = (_e = route.options).head) == null ? void 0 : _f.call(_e, assetContext);
1591
- match.links = headFnContent == null ? void 0 : headFnContent.links;
1592
- match.headScripts = headFnContent == null ? void 0 : headFnContent.scripts;
1593
- match.meta = headFnContent == null ? void 0 : headFnContent.meta;
1594
- match.scripts = (_h = (_g = route.options).scripts) == null ? void 0 : _h.call(_g, assetContext);
1595
- }
1596
1660
  });
1597
1661
  return matches;
1598
1662
  }
@@ -1656,141 +1720,6 @@ function routeNeedsPreload(route) {
1656
1720
  }
1657
1721
  return false;
1658
1722
  }
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
1723
  exports.PathParamError = PathParamError;
1795
1724
  exports.RouterCore = RouterCore;
1796
1725
  exports.SearchParamError = SearchParamError;
@@ -1798,7 +1727,5 @@ exports.componentTypes = componentTypes;
1798
1727
  exports.defaultSerializeError = defaultSerializeError;
1799
1728
  exports.getInitialRouterState = getInitialRouterState;
1800
1729
  exports.getLocationChangeInfo = getLocationChangeInfo;
1801
- exports.getMatchedRoutes = getMatchedRoutes;
1802
1730
  exports.lazyFn = lazyFn;
1803
- exports.processRouteTree = processRouteTree;
1804
1731
  //# sourceMappingURL=router.cjs.map