@tanstack/router-core 1.125.4 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
- "version": "1.125.4",
3
+ "version": "1.126.2",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -42,5 +42,6 @@ export type BuildLocationFn = <
42
42
  opts: ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
43
43
  leaveParams?: boolean
44
44
  _includeValidateSearch?: boolean
45
+ _isNavigate?: boolean
45
46
  },
46
47
  ) => ParsedLocation
package/src/router.ts CHANGED
@@ -441,6 +441,7 @@ export interface BuildNextOptions {
441
441
  href?: string
442
442
  _fromLocation?: ParsedLocation
443
443
  unsafeRelative?: 'path'
444
+ _isNavigate?: boolean
444
445
  }
445
446
 
446
447
  type NavigationEventInfo = {
@@ -1419,11 +1420,11 @@ export class RouterCore<
1419
1420
  // We allow the caller to override the current location
1420
1421
  const currentLocation = dest._fromLocation || this.latestLocation
1421
1422
 
1422
- const allFromMatches = this.matchRoutes(currentLocation, {
1423
+ const allCurrentLocationMatches = this.matchRoutes(currentLocation, {
1423
1424
  _buildLocation: true,
1424
1425
  })
1425
1426
 
1426
- const lastMatch = last(allFromMatches)!
1427
+ const lastMatch = last(allCurrentLocationMatches)!
1427
1428
 
1428
1429
  // First let's find the starting pathname
1429
1430
  // By default, start with the current location
@@ -1442,12 +1443,29 @@ export class RouterCore<
1442
1443
  fromPath = currentLocation.pathname
1443
1444
  } else if (routeIsChanging && dest.from) {
1444
1445
  fromPath = dest.from
1445
- const existingFrom = [...allFromMatches].reverse().find((d) => {
1446
- return this.comparePaths(d.fullPath, fromPath)
1447
- })
1448
1446
 
1449
- if (!existingFrom) {
1450
- console.warn(`Could not find match for from: ${fromPath}`)
1447
+ // do this check only on navigations during test or development
1448
+ if (process.env.NODE_ENV !== 'production' && dest._isNavigate) {
1449
+ const allFromMatches = this.getMatchedRoutes(
1450
+ dest.from,
1451
+ undefined,
1452
+ ).matchedRoutes
1453
+
1454
+ const matchedFrom = [...allCurrentLocationMatches]
1455
+ .reverse()
1456
+ .find((d) => {
1457
+ return this.comparePaths(d.fullPath, fromPath)
1458
+ })
1459
+
1460
+ const matchedCurrent = [...allFromMatches].reverse().find((d) => {
1461
+ return this.comparePaths(d.fullPath, currentLocation.pathname)
1462
+ })
1463
+
1464
+ // for from to be invalid it shouldn't just be unmatched to currentLocation
1465
+ // but the currentLocation should also be unmatched to from
1466
+ if (!matchedFrom && !matchedCurrent) {
1467
+ console.warn(`Could not find match for from: ${fromPath}`)
1468
+ }
1451
1469
  }
1452
1470
  }
1453
1471
 
@@ -1777,6 +1795,7 @@ export class RouterCore<
1777
1795
  ...rest,
1778
1796
  href,
1779
1797
  to: to as string,
1798
+ _isNavigate: true,
1780
1799
  })
1781
1800
  }
1782
1801