@tanstack/router-core 1.171.17 → 1.171.18

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.
@@ -242,33 +242,33 @@ var RouterCore = class {
242
242
  return this.matchRoutesInternal(pathnameOrNext, locationSearchOrOpts);
243
243
  };
244
244
  this.getMatchedRoutes = (pathname) => {
245
- const routeParams = Object.create(null);
245
+ const rawParams = Object.create(null);
246
246
  const match = require_new_process_route_tree.findRouteMatch(require_path.trimPathRight(pathname), this.processedTree, true);
247
- if (match) Object.assign(routeParams, match.rawParams);
248
- return {
249
- matchedRoutes: match?.branch || [this.routesById["__root__"]],
250
- routeParams,
251
- foundRoute: match?.route
252
- };
247
+ if (match) Object.assign(rawParams, match.rawParams);
248
+ return [
249
+ match?.branch || [this.routesById["__root__"]],
250
+ rawParams,
251
+ match?.route
252
+ ];
253
253
  };
254
254
  this.buildLocation = (opts) => {
255
255
  const build = (dest = {}) => {
256
256
  const currentLocation = dest._fromLocation || this._pendingLocation || this.latestLocation;
257
257
  const lightweightResult = this.matchRoutesLightweight(currentLocation);
258
258
  if (dest.from && process.env.NODE_ENV !== "production" && dest._isNavigate) {
259
- const allFromMatches = this.getMatchedRoutes(dest.from).matchedRoutes;
260
- const matchedFrom = require_utils.findLast(lightweightResult.matchedRoutes, (d) => {
259
+ const [allFromMatches] = this.getMatchedRoutes(dest.from);
260
+ const matchedFrom = require_utils.findLast(lightweightResult[0], (d) => {
261
261
  return comparePaths(d.fullPath, dest.from);
262
262
  });
263
263
  const matchedCurrent = require_utils.findLast(allFromMatches, (d) => {
264
- return comparePaths(d.fullPath, lightweightResult.fullPath);
264
+ return comparePaths(d.fullPath, lightweightResult[1]);
265
265
  });
266
266
  if (!matchedFrom && !matchedCurrent) console.warn(`Could not find match for from: ${dest.from}`);
267
267
  }
268
- const defaultedFromPath = dest.unsafeRelative === "path" ? currentLocation.pathname : dest.from ?? lightweightResult.fullPath;
268
+ const defaultedFromPath = dest.unsafeRelative === "path" ? currentLocation.pathname : dest.from ?? lightweightResult[1];
269
269
  const destTo = dest.to ? `${dest.to}` : void 0;
270
- const fromSearch = lightweightResult.search;
271
- const fromParams = Object.assign(Object.create(null), lightweightResult.params);
270
+ const fromSearch = lightweightResult[2];
271
+ const fromParams = Object.assign(Object.create(null), lightweightResult[3]);
272
272
  const sourcePath = destTo?.charCodeAt(0) === 47 ? "/" : this.resolvePathWithBase(defaultedFromPath, ".");
273
273
  const nextTo = destTo ? this.resolvePathWithBase(sourcePath, destTo) : sourcePath;
274
274
  const nextParams = resolveNextParams(dest.params, fromParams);
@@ -277,9 +277,9 @@ var RouterCore = class {
277
277
  if (destRoute) destRoutes = this.getRouteBranch(destRoute);
278
278
  else if (nextTo.includes("$")) destRoutes = [];
279
279
  else {
280
- const destMatchResult = this.getMatchedRoutes(nextTo);
281
- destRoutes = destMatchResult.matchedRoutes;
282
- if (this.options.notFoundRoute && (!destMatchResult.foundRoute || destMatchResult.foundRoute.path !== "/" && destMatchResult.routeParams["**"])) destRoutes = [...destRoutes, this.options.notFoundRoute];
280
+ const [matchedRoutes, rawParams, foundRoute] = this.getMatchedRoutes(nextTo);
281
+ destRoutes = matchedRoutes;
282
+ if (this.options.notFoundRoute && (!foundRoute || foundRoute.path !== "/" && rawParams["**"])) destRoutes = [...destRoutes, this.options.notFoundRoute];
283
283
  }
284
284
  if (destRoutes.length && require_utils.hasKeys(nextParams)) for (const route of destRoutes) {
285
285
  const fn = route.options.params?.stringify ?? route.options.stringifyParams;
@@ -294,8 +294,8 @@ var RouterCore = class {
294
294
  server: this.isServer
295
295
  }).interpolatedPath).path;
296
296
  if (process.env.NODE_ENV !== "production" && destRoute && !opts.leaveParams) try {
297
- const roundTrip = this.getMatchedRoutes(nextPathname);
298
- if (roundTrip.foundRoute?.id !== destRoute.id) console.warn(`Generated path "${nextPathname}" for route "${destRoute.id}" matched route "${roundTrip.foundRoute?.id}" instead. This can happen when multiple route templates resolve to the same URL. Use the route template that matches the intended route, or adjust params.stringify if it changed the target path.`);
297
+ const foundRoute = this.getMatchedRoutes(nextPathname)[2];
298
+ if (foundRoute?.id !== destRoute.id) console.warn(`Generated path "${nextPathname}" for route "${destRoute.id}" matched route "${foundRoute?.id}" instead. This can happen when multiple route templates resolve to the same URL. Use the route template that matches the intended route, or adjust params.stringify if it changed the target path.`);
299
299
  } catch {}
300
300
  let nextSearch = fromSearch;
301
301
  if (opts._includeValidateSearch && this.options.search?.strict) {
@@ -662,11 +662,10 @@ var RouterCore = class {
662
662
  return branch;
663
663
  }
664
664
  matchRoutesInternal(next, opts) {
665
- const matchedRoutesResult = this.getMatchedRoutes(next.pathname);
666
- const { foundRoute, routeParams } = matchedRoutesResult;
667
- let { matchedRoutes } = matchedRoutesResult;
665
+ const [initialMatchedRoutes, rawParams, foundRoute] = this.getMatchedRoutes(next.pathname);
666
+ let matchedRoutes = initialMatchedRoutes;
668
667
  let isGlobalNotFound = false;
669
- if (foundRoute ? foundRoute.path !== "/" && routeParams["**"] : require_path.trimPathRight(next.pathname)) if (this.options.notFoundRoute) matchedRoutes = [...matchedRoutes, this.options.notFoundRoute];
668
+ if (foundRoute ? foundRoute.path !== "/" && rawParams["**"] : require_path.trimPathRight(next.pathname)) if (this.options.notFoundRoute) matchedRoutes = [...matchedRoutes, this.options.notFoundRoute];
670
669
  else isGlobalNotFound = true;
671
670
  const _notFoundRouteId = isGlobalNotFound ? findGlobalNotFoundRouteId(this.options.notFoundMode, matchedRoutes) : void 0;
672
671
  const matches = new Array(matchedRoutes.length);
@@ -675,6 +674,7 @@ var RouterCore = class {
675
674
  const match = committed[index];
676
675
  return match?.routeId === route.id ? match : route === this.options.notFoundRoute ? committed.find((candidate) => candidate.routeId === route.id) : void 0;
677
676
  };
677
+ let strictParams;
678
678
  for (let index = 0; index < matchedRoutes.length; index++) {
679
679
  const route = matchedRoutes[index];
680
680
  const parentMatch = matches[index - 1];
@@ -714,14 +714,14 @@ var RouterCore = class {
714
714
  }
715
715
  const { interpolatedPath, usedParams } = require_path.interpolatePath({
716
716
  path: route.fullPath,
717
- params: routeParams,
717
+ params: rawParams,
718
718
  decoder: this.pathParamsDecoder,
719
719
  server: this.isServer
720
720
  });
721
721
  const matchId = route.id + interpolatedPath + loaderDepsHash;
722
722
  const previousMatch = previousAt(route, index);
723
723
  const existingMatch = process.env.NODE_ENV !== "production" && opts?._rematerialize ? void 0 : this._cache.get(matchId) ?? (previousMatch?.id === matchId ? previousMatch : void 0);
724
- const strictParams = existingMatch?._strictParams ?? usedParams;
724
+ strictParams = existingMatch?._strictParams ?? Object.assign(usedParams, strictParams);
725
725
  let paramsError;
726
726
  if (!existingMatch) try {
727
727
  extractStrictParams(route, strictParams);
@@ -730,14 +730,11 @@ var RouterCore = class {
730
730
  else paramsError = new PathParamError(err.message, { cause: err });
731
731
  if (opts?.throwOnError) throw paramsError;
732
732
  }
733
- Object.assign(routeParams, strictParams);
734
733
  const cause = previousMatch ? "stay" : "enter";
735
734
  let match;
736
735
  if (existingMatch) match = {
737
736
  ...existingMatch,
738
737
  cause,
739
- params: previousMatch?.params ?? routeParams,
740
- _strictParams: strictParams,
741
738
  search: previousMatch ? require_utils.nullReplaceEqualDeep(previousMatch.search, preMatchSearch) : require_utils.nullReplaceEqualDeep(existingMatch.search, preMatchSearch),
742
739
  _strictSearch: strictMatchSearch,
743
740
  searchError
@@ -749,7 +746,7 @@ var RouterCore = class {
749
746
  ssr: _tanstack_router_core_isServer.isServer ?? this.isServer ? void 0 : route.options.ssr,
750
747
  index,
751
748
  routeId: route.id,
752
- params: previousMatch?.params ?? routeParams,
749
+ params: previousMatch?.params ?? strictParams,
753
750
  _strictParams: strictParams,
754
751
  pathname: interpolatedPath,
755
752
  updatedAt: Date.now(),
@@ -777,7 +774,7 @@ var RouterCore = class {
777
774
  }
778
775
  for (let index = 0; index < matches.length; index++) {
779
776
  const match = matches[index];
780
- match.params = match.cause === "stay" ? require_utils.nullReplaceEqualDeep(match.params, routeParams) : routeParams;
777
+ match.params = match.cause === "stay" ? require_utils.nullReplaceEqualDeep(match.params, strictParams) : strictParams;
781
778
  if (opts?._controller) match.context = {};
782
779
  }
783
780
  return matches;
@@ -793,7 +790,7 @@ var RouterCore = class {
793
790
  const lastStateMatchId = lastStateMatch?.id;
794
791
  const cached = this.lightweightCache.get(location);
795
792
  if (cached && cached[0] === lastStateMatchId) return cached[1];
796
- const { matchedRoutes, routeParams } = this.getMatchedRoutes(location.pathname);
793
+ const [matchedRoutes, rawParams] = this.getMatchedRoutes(location.pathname);
797
794
  const lastRoute = require_utils.last(matchedRoutes);
798
795
  const accumulatedSearch = { ...location.search };
799
796
  for (const route of matchedRoutes) try {
@@ -803,18 +800,18 @@ var RouterCore = class {
803
800
  let params;
804
801
  if (canReuseParams) params = lastStateMatch.params;
805
802
  else {
806
- const strictParams = Object.assign(Object.create(null), routeParams);
803
+ const strictParams = Object.assign(Object.create(null), rawParams);
807
804
  for (const route of matchedRoutes) try {
808
805
  extractStrictParams(route, strictParams);
809
806
  } catch {}
810
807
  params = strictParams;
811
808
  }
812
- const result = {
809
+ const result = [
813
810
  matchedRoutes,
814
- fullPath: lastRoute.fullPath,
815
- search: accumulatedSearch,
811
+ lastRoute.fullPath,
812
+ accumulatedSearch,
816
813
  params
817
- };
814
+ ];
818
815
  this.lightweightCache.set(location, [lastStateMatchId, result]);
819
816
  return result;
820
817
  }