@tanstack/router-core 1.125.3 → 1.126.2

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.
@@ -23,4 +23,5 @@ export type NavigateFn = <TRouter extends RegisteredRouter, TTo extends string |
23
23
  export type BuildLocationFn = <TRouter extends RegisteredRouter, TTo extends string | undefined, TFrom extends RoutePaths<TRouter['routeTree']> | string = string, TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom, TMaskTo extends string = ''>(opts: ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
24
24
  leaveParams?: boolean;
25
25
  _includeValidateSearch?: boolean;
26
+ _isNavigate?: boolean;
26
27
  }) => ParsedLocation;
@@ -231,21 +231,31 @@ class RouterCore {
231
231
  const build = (dest = {}) => {
232
232
  var _a;
233
233
  const currentLocation = dest._fromLocation || this.latestLocation;
234
- const allFromMatches = this.matchRoutes(currentLocation, {
234
+ const allCurrentLocationMatches = this.matchRoutes(currentLocation, {
235
235
  _buildLocation: true
236
236
  });
237
- const lastMatch = utils.last(allFromMatches);
237
+ const lastMatch = utils.last(allCurrentLocationMatches);
238
238
  let fromPath = lastMatch.fullPath;
239
- const routeIsChanging = !!dest.to && dest.to !== fromPath && this.resolvePathWithBase(fromPath, `${dest.to}`) !== fromPath;
239
+ const toPath = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : this.resolvePathWithBase(fromPath, ".");
240
+ const routeIsChanging = !!dest.to && !this.comparePaths(dest.to.toString(), fromPath) && !this.comparePaths(toPath, fromPath);
240
241
  if (dest.unsafeRelative === "path") {
241
242
  fromPath = currentLocation.pathname;
242
243
  } else if (routeIsChanging && dest.from) {
243
244
  fromPath = dest.from;
244
- const existingFrom = [...allFromMatches].reverse().find((d) => {
245
- return d.fullPath === fromPath || d.fullPath === path.joinPaths([fromPath, "/"]);
246
- });
247
- if (!existingFrom) {
248
- console.warn(`Could not find match for from: ${dest.from}`);
245
+ if (process.env.NODE_ENV !== "production" && dest._isNavigate) {
246
+ const allFromMatches = this.getMatchedRoutes(
247
+ dest.from,
248
+ void 0
249
+ ).matchedRoutes;
250
+ const matchedFrom = [...allCurrentLocationMatches].reverse().find((d) => {
251
+ return this.comparePaths(d.fullPath, fromPath);
252
+ });
253
+ const matchedCurrent = [...allFromMatches].reverse().find((d) => {
254
+ return this.comparePaths(d.fullPath, currentLocation.pathname);
255
+ });
256
+ if (!matchedFrom && !matchedCurrent) {
257
+ console.warn(`Could not find match for from: ${fromPath}`);
258
+ }
249
259
  }
250
260
  }
251
261
  const fromSearch = lastMatch.search;
@@ -483,7 +493,8 @@ class RouterCore {
483
493
  return this.buildAndCommitLocation({
484
494
  ...rest,
485
495
  href,
486
- to
496
+ to,
497
+ _isNavigate: true
487
498
  });
488
499
  };
489
500
  this.beforeLoad = () => {
@@ -1670,6 +1681,9 @@ class RouterCore {
1670
1681
  });
1671
1682
  return matches;
1672
1683
  }
1684
+ comparePaths(path1, path2) {
1685
+ return path1.replace(/(.+)\/$/, "$1") === path2.replace(/(.+)\/$/, "$1");
1686
+ }
1673
1687
  }
1674
1688
  class SearchParamError extends Error {
1675
1689
  }