@tanstack/router-core 1.154.3 → 1.154.4

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.154.3",
3
+ "version": "1.154.4",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/router.ts CHANGED
@@ -594,6 +594,12 @@ export interface MatchRoutesOpts {
594
594
  snapshot?: MatchSnapshot
595
595
  }
596
596
 
597
+ export interface MatchRoutesResult {
598
+ matches: Array<AnyRouteMatch>
599
+ /** Raw string params extracted from path (before parsing) */
600
+ rawParams: Record<string, string>
601
+ }
602
+
597
603
  export type InferRouterContext<TRouteTree extends AnyRoute> =
598
604
  TRouteTree['types']['routerContext']
599
605
 
@@ -1265,16 +1271,17 @@ export class RouterCore<
1265
1271
  search: locationSearchOrOpts,
1266
1272
  } as ParsedLocation,
1267
1273
  opts,
1268
- )
1274
+ ).matches
1269
1275
  }
1270
1276
 
1271
1277
  return this.matchRoutesInternal(pathnameOrNext, locationSearchOrOpts)
1278
+ .matches
1272
1279
  }
1273
1280
 
1274
1281
  private matchRoutesInternal(
1275
1282
  next: ParsedLocation,
1276
1283
  opts?: MatchRoutesOpts,
1277
- ): Array<AnyRouteMatch> {
1284
+ ): MatchRoutesResult {
1278
1285
  // Fast-path: use snapshot hint if valid
1279
1286
  const snapshot = opts?.snapshot
1280
1287
  const snapshotValid =
@@ -1284,6 +1291,7 @@ export class RouterCore<
1284
1291
 
1285
1292
  let matchedRoutes: ReadonlyArray<AnyRoute>
1286
1293
  let routeParams: Record<string, string>
1294
+ let rawParams: Record<string, string>
1287
1295
  let globalNotFoundRouteId: string | undefined
1288
1296
  let parsedParams: Record<string, unknown>
1289
1297
 
@@ -1291,6 +1299,7 @@ export class RouterCore<
1291
1299
  // Rebuild matched routes from snapshot
1292
1300
  matchedRoutes = snapshot.routeIds.map((id) => this.routesById[id]!)
1293
1301
  routeParams = { ...snapshot.params }
1302
+ rawParams = { ...snapshot.params }
1294
1303
  globalNotFoundRouteId = snapshot.globalNotFoundRouteId
1295
1304
  parsedParams = snapshot.parsedParams
1296
1305
  } else {
@@ -1298,6 +1307,7 @@ export class RouterCore<
1298
1307
  const matchedRoutesResult = this.getMatchedRoutes(next.pathname)
1299
1308
  const { foundRoute, routeParams: rp } = matchedRoutesResult
1300
1309
  routeParams = rp
1310
+ rawParams = { ...rp } // Capture before routeParams gets modified
1301
1311
  matchedRoutes = matchedRoutesResult.matchedRoutes
1302
1312
  parsedParams = matchedRoutesResult.parsedParams
1303
1313
 
@@ -1642,7 +1652,7 @@ export class RouterCore<
1642
1652
  }
1643
1653
  })
1644
1654
 
1645
- return matches
1655
+ return { matches, rawParams }
1646
1656
  }
1647
1657
 
1648
1658
  getMatchedRoutes: GetMatchRoutesFn = (pathname) => {
@@ -1765,9 +1775,10 @@ export class RouterCore<
1765
1775
  params: nextParams,
1766
1776
  }).interpolatedPath
1767
1777
 
1768
- const destMatches = this.matchRoutes(interpolatedNextTo, undefined, {
1769
- _buildLocation: true,
1770
- })
1778
+ const { matches: destMatches, rawParams } = this.matchRoutesInternal(
1779
+ { pathname: interpolatedNextTo } as ParsedLocation,
1780
+ { _buildLocation: true },
1781
+ )
1771
1782
  const destRoutes = destMatches.map(
1772
1783
  (d) => this.looseRoutesById[d.routeId]!,
1773
1784
  )
@@ -1856,10 +1867,15 @@ export class RouterCore<
1856
1867
  nextState = replaceEqualDeep(currentLocation.state, nextState)
1857
1868
 
1858
1869
  // Build match snapshot for fast-path on back/forward navigation
1859
- // Use destRoutes and nextParams directly (after stringify)
1870
+ // Use raw params captured during matchRoutesInternal (needed for literal path navigation
1871
+ // where nextParams may be empty but path contains param values)
1872
+ const snapshotParams = {
1873
+ ...rawParams,
1874
+ ...nextParams,
1875
+ }
1860
1876
  const matchSnapshot = buildMatchSnapshotFromRoutes({
1861
1877
  routes: destRoutes,
1862
- params: nextParams,
1878
+ params: snapshotParams,
1863
1879
  searchStr,
1864
1880
  globalNotFoundRouteId: globalNotFoundMatch?.routeId,
1865
1881
  })