@tanstack/router-core 1.154.8 → 1.154.12

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.
@@ -316,14 +316,21 @@ class RouterCore {
316
316
  path: nextTo,
317
317
  params: nextParams
318
318
  }).interpolatedPath;
319
- const { matches: destMatches, rawParams } = this.matchRoutesInternal(
320
- { pathname: interpolatedNextTo },
321
- { _buildLocation: true }
322
- );
323
- const destRoutes = destMatches.map(
324
- (d) => this.looseRoutesById[d.routeId]
325
- );
326
- const globalNotFoundMatch = destMatches.find((m) => m.globalNotFound);
319
+ const destMatchResult = this.getMatchedRoutes(interpolatedNextTo);
320
+ let destRoutes = destMatchResult.matchedRoutes;
321
+ const rawParams = destMatchResult.routeParams;
322
+ const isGlobalNotFound = destMatchResult.foundRoute ? destMatchResult.foundRoute.path !== "/" && destMatchResult.routeParams["**"] : path.trimPathRight(interpolatedNextTo);
323
+ let globalNotFoundRouteId;
324
+ if (isGlobalNotFound) {
325
+ if (this.options.notFoundRoute) {
326
+ destRoutes = [...destRoutes, this.options.notFoundRoute];
327
+ } else {
328
+ globalNotFoundRouteId = findGlobalNotFoundRouteId(
329
+ this.options.notFoundMode,
330
+ destRoutes
331
+ );
332
+ }
333
+ }
327
334
  if (Object.keys(nextParams).length > 0) {
328
335
  for (const route of destRoutes) {
329
336
  const fn = route.options.params?.stringify ?? route.options.stringifyParams;
@@ -382,7 +389,7 @@ class RouterCore {
382
389
  routes: destRoutes,
383
390
  params: snapshotParams,
384
391
  searchStr,
385
- globalNotFoundRouteId: globalNotFoundMatch?.routeId
392
+ globalNotFoundRouteId
386
393
  });
387
394
  const fullPath = `${nextPathname}${searchStr}${hashStr}`;
388
395
  const url = new URL(fullPath, this.origin);
@@ -1106,20 +1113,7 @@ class RouterCore {
1106
1113
  isGlobalNotFound = true;
1107
1114
  }
1108
1115
  }
1109
- globalNotFoundRouteId = (() => {
1110
- if (!isGlobalNotFound) {
1111
- return void 0;
1112
- }
1113
- if (this.options.notFoundMode !== "root") {
1114
- for (let i = matchedRoutes.length - 1; i >= 0; i--) {
1115
- const route = matchedRoutes[i];
1116
- if (route.children) {
1117
- return route.id;
1118
- }
1119
- }
1120
- }
1121
- return root.rootRouteId;
1122
- })();
1116
+ globalNotFoundRouteId = isGlobalNotFound ? findGlobalNotFoundRouteId(this.options.notFoundMode, matchedRoutes) : void 0;
1123
1117
  }
1124
1118
  const matches = [];
1125
1119
  const getParentContext = (parentMatch) => {
@@ -1519,6 +1513,17 @@ function applySearchMiddleware({
1519
1513
  };
1520
1514
  return applyNext(0, search);
1521
1515
  }
1516
+ function findGlobalNotFoundRouteId(notFoundMode, routes) {
1517
+ if (notFoundMode !== "root") {
1518
+ for (let i = routes.length - 1; i >= 0; i--) {
1519
+ const route = routes[i];
1520
+ if (route.children) {
1521
+ return route.id;
1522
+ }
1523
+ }
1524
+ }
1525
+ return root.rootRouteId;
1526
+ }
1522
1527
  exports.PathParamError = PathParamError;
1523
1528
  exports.RouterCore = RouterCore;
1524
1529
  exports.SearchParamError = SearchParamError;