@tanstack/router-core 1.125.1 → 1.125.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.125.1",
3
+ "version": "1.125.4",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/path.ts CHANGED
@@ -330,6 +330,21 @@ export function interpolatePath({
330
330
  usedParams._splat = params._splat
331
331
  const segmentPrefix = segment.prefixSegment || ''
332
332
  const segmentSuffix = segment.suffixSegment || ''
333
+
334
+ // Check if _splat parameter is missing
335
+ if (!('_splat' in params)) {
336
+ isMissingParams = true
337
+ // For missing splat parameters, just return the prefix and suffix without the wildcard
338
+ if (leaveWildcards) {
339
+ return `${segmentPrefix}${segment.value}${segmentSuffix}`
340
+ }
341
+ // If there is a prefix or suffix, return them joined, otherwise omit the segment
342
+ if (segmentPrefix || segmentSuffix) {
343
+ return `${segmentPrefix}${segmentSuffix}`
344
+ }
345
+ return undefined
346
+ }
347
+
333
348
  const value = encodeParam('_splat')
334
349
  if (leaveWildcards) {
335
350
  return `${segmentPrefix}${segment.value}${value ?? ''}${segmentSuffix}`
package/src/router.ts CHANGED
@@ -1406,6 +1406,10 @@ export class RouterCore<
1406
1406
  })
1407
1407
  }
1408
1408
 
1409
+ private comparePaths(path1: string, path2: string) {
1410
+ return path1.replace(/(.+)\/$/, '$1') === path2.replace(/(.+)\/$/, '$1')
1411
+ }
1412
+
1409
1413
  buildLocation: BuildLocationFn = (opts) => {
1410
1414
  const build = (
1411
1415
  dest: BuildNextOptions & {
@@ -1424,11 +1428,14 @@ export class RouterCore<
1424
1428
  // First let's find the starting pathname
1425
1429
  // By default, start with the current location
1426
1430
  let fromPath = lastMatch.fullPath
1431
+ const toPath = dest.to
1432
+ ? this.resolvePathWithBase(fromPath, `${dest.to}`)
1433
+ : this.resolvePathWithBase(fromPath, '.')
1427
1434
 
1428
1435
  const routeIsChanging =
1429
1436
  !!dest.to &&
1430
- dest.to !== fromPath &&
1431
- this.resolvePathWithBase(fromPath, `${dest.to}`) !== fromPath
1437
+ !this.comparePaths(dest.to.toString(), fromPath) &&
1438
+ !this.comparePaths(toPath, fromPath)
1432
1439
 
1433
1440
  // If the route is changing we need to find the relative fromPath
1434
1441
  if (dest.unsafeRelative === 'path') {
@@ -1436,13 +1443,11 @@ export class RouterCore<
1436
1443
  } else if (routeIsChanging && dest.from) {
1437
1444
  fromPath = dest.from
1438
1445
  const existingFrom = [...allFromMatches].reverse().find((d) => {
1439
- return (
1440
- d.fullPath === fromPath || d.fullPath === joinPaths([fromPath, '/'])
1441
- )
1446
+ return this.comparePaths(d.fullPath, fromPath)
1442
1447
  })
1443
1448
 
1444
1449
  if (!existingFrom) {
1445
- console.warn(`Could not find match for from: ${dest.from}`)
1450
+ console.warn(`Could not find match for from: ${fromPath}`)
1446
1451
  }
1447
1452
  }
1448
1453