@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.
- package/dist/cjs/RouterProvider.d.cts +1 -0
- package/dist/cjs/router.cjs +23 -9
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +2 -0
- package/dist/esm/RouterProvider.d.ts +1 -0
- package/dist/esm/router.d.ts +2 -0
- package/dist/esm/router.js +23 -9
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/RouterProvider.ts +1 -0
- package/src/router.ts +35 -11
package/package.json
CHANGED
package/src/RouterProvider.ts
CHANGED
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 = {
|
|
@@ -1406,6 +1407,10 @@ export class RouterCore<
|
|
|
1406
1407
|
})
|
|
1407
1408
|
}
|
|
1408
1409
|
|
|
1410
|
+
private comparePaths(path1: string, path2: string) {
|
|
1411
|
+
return path1.replace(/(.+)\/$/, '$1') === path2.replace(/(.+)\/$/, '$1')
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1409
1414
|
buildLocation: BuildLocationFn = (opts) => {
|
|
1410
1415
|
const build = (
|
|
1411
1416
|
dest: BuildNextOptions & {
|
|
@@ -1415,34 +1420,52 @@ export class RouterCore<
|
|
|
1415
1420
|
// We allow the caller to override the current location
|
|
1416
1421
|
const currentLocation = dest._fromLocation || this.latestLocation
|
|
1417
1422
|
|
|
1418
|
-
const
|
|
1423
|
+
const allCurrentLocationMatches = this.matchRoutes(currentLocation, {
|
|
1419
1424
|
_buildLocation: true,
|
|
1420
1425
|
})
|
|
1421
1426
|
|
|
1422
|
-
const lastMatch = last(
|
|
1427
|
+
const lastMatch = last(allCurrentLocationMatches)!
|
|
1423
1428
|
|
|
1424
1429
|
// First let's find the starting pathname
|
|
1425
1430
|
// By default, start with the current location
|
|
1426
1431
|
let fromPath = lastMatch.fullPath
|
|
1432
|
+
const toPath = dest.to
|
|
1433
|
+
? this.resolvePathWithBase(fromPath, `${dest.to}`)
|
|
1434
|
+
: this.resolvePathWithBase(fromPath, '.')
|
|
1427
1435
|
|
|
1428
1436
|
const routeIsChanging =
|
|
1429
1437
|
!!dest.to &&
|
|
1430
|
-
dest.to
|
|
1431
|
-
this.
|
|
1438
|
+
!this.comparePaths(dest.to.toString(), fromPath) &&
|
|
1439
|
+
!this.comparePaths(toPath, fromPath)
|
|
1432
1440
|
|
|
1433
1441
|
// If the route is changing we need to find the relative fromPath
|
|
1434
1442
|
if (dest.unsafeRelative === 'path') {
|
|
1435
1443
|
fromPath = currentLocation.pathname
|
|
1436
1444
|
} else if (routeIsChanging && dest.from) {
|
|
1437
1445
|
fromPath = dest.from
|
|
1438
|
-
const existingFrom = [...allFromMatches].reverse().find((d) => {
|
|
1439
|
-
return (
|
|
1440
|
-
d.fullPath === fromPath || d.fullPath === joinPaths([fromPath, '/'])
|
|
1441
|
-
)
|
|
1442
|
-
})
|
|
1443
1446
|
|
|
1444
|
-
|
|
1445
|
-
|
|
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
|
+
}
|
|
1446
1469
|
}
|
|
1447
1470
|
}
|
|
1448
1471
|
|
|
@@ -1772,6 +1795,7 @@ export class RouterCore<
|
|
|
1772
1795
|
...rest,
|
|
1773
1796
|
href,
|
|
1774
1797
|
to: to as string,
|
|
1798
|
+
_isNavigate: true,
|
|
1775
1799
|
})
|
|
1776
1800
|
}
|
|
1777
1801
|
|