@tanstack/router-core 1.120.3 → 1.120.4-alpha.1

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.
Files changed (51) hide show
  1. package/dist/cjs/fileRoute.d.cts +6 -2
  2. package/dist/cjs/index.cjs +4 -0
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/index.d.cts +5 -5
  5. package/dist/cjs/link.cjs.map +1 -1
  6. package/dist/cjs/link.d.cts +5 -0
  7. package/dist/cjs/path.cjs +130 -16
  8. package/dist/cjs/path.cjs.map +1 -1
  9. package/dist/cjs/path.d.cts +17 -0
  10. package/dist/cjs/redirect.cjs +19 -14
  11. package/dist/cjs/redirect.cjs.map +1 -1
  12. package/dist/cjs/redirect.d.cts +10 -7
  13. package/dist/cjs/route.cjs +12 -1
  14. package/dist/cjs/route.cjs.map +1 -1
  15. package/dist/cjs/route.d.cts +7 -8
  16. package/dist/cjs/router.cjs +227 -155
  17. package/dist/cjs/router.cjs.map +1 -1
  18. package/dist/cjs/router.d.cts +45 -3
  19. package/dist/cjs/typePrimitives.d.cts +2 -2
  20. package/dist/cjs/utils.cjs.map +1 -1
  21. package/dist/cjs/utils.d.cts +2 -0
  22. package/dist/esm/fileRoute.d.ts +6 -2
  23. package/dist/esm/index.d.ts +5 -5
  24. package/dist/esm/index.js +7 -3
  25. package/dist/esm/link.d.ts +5 -0
  26. package/dist/esm/link.js.map +1 -1
  27. package/dist/esm/path.d.ts +17 -0
  28. package/dist/esm/path.js +130 -16
  29. package/dist/esm/path.js.map +1 -1
  30. package/dist/esm/redirect.d.ts +10 -7
  31. package/dist/esm/redirect.js +20 -15
  32. package/dist/esm/redirect.js.map +1 -1
  33. package/dist/esm/route.d.ts +7 -8
  34. package/dist/esm/route.js +12 -1
  35. package/dist/esm/route.js.map +1 -1
  36. package/dist/esm/router.d.ts +45 -3
  37. package/dist/esm/router.js +230 -158
  38. package/dist/esm/router.js.map +1 -1
  39. package/dist/esm/typePrimitives.d.ts +2 -2
  40. package/dist/esm/utils.d.ts +2 -0
  41. package/dist/esm/utils.js.map +1 -1
  42. package/package.json +2 -2
  43. package/src/fileRoute.ts +90 -1
  44. package/src/index.ts +13 -3
  45. package/src/link.ts +5 -0
  46. package/src/path.ts +181 -16
  47. package/src/redirect.ts +37 -22
  48. package/src/route.ts +92 -20
  49. package/src/router.ts +326 -209
  50. package/src/typePrimitives.ts +2 -2
  51. package/src/utils.ts +14 -0
package/src/route.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import invariant from 'tiny-invariant'
1
2
  import { joinPaths, trimPathLeft } from './path'
2
3
  import { notFound } from './not-found'
3
4
  import { rootRouteId } from './root'
@@ -20,6 +21,8 @@ import type {
20
21
  Constrain,
21
22
  Expand,
22
23
  IntersectAssign,
24
+ LooseAsyncReturnType,
25
+ LooseReturnType,
23
26
  NoInfer,
24
27
  } from './utils'
25
28
  import type {
@@ -270,20 +273,6 @@ export type TrimPathRight<T extends string> = T extends '/'
270
273
  ? TrimPathRight<U>
271
274
  : T
272
275
 
273
- export type LooseReturnType<T> = T extends (
274
- ...args: Array<any>
275
- ) => infer TReturn
276
- ? TReturn
277
- : never
278
-
279
- export type LooseAsyncReturnType<T> = T extends (
280
- ...args: Array<any>
281
- ) => infer TReturn
282
- ? TReturn extends Promise<infer TReturn>
283
- ? TReturn
284
- : TReturn
285
- : never
286
-
287
276
  export type ContextReturnType<TContextFn> = unknown extends TContextFn
288
277
  ? TContextFn
289
278
  : LooseReturnType<TContextFn> extends never
@@ -448,7 +437,7 @@ export interface RouteExtensions<in out TId, in out TFullPath> {
448
437
  }
449
438
 
450
439
  export type RouteLazyFn<TRoute extends AnyRoute> = (
451
- lazyFn: () => Promise<LazyRoute>,
440
+ lazyFn: () => Promise<LazyRoute<TRoute>>,
452
441
  ) => TRoute
453
442
 
454
443
  export type RouteAddChildrenFn<
@@ -602,7 +591,26 @@ export interface Route<
602
591
  >
603
592
  isRoot: TParentRoute extends AnyRoute ? true : false
604
593
  _componentsPromise?: Promise<Array<void>>
605
- lazyFn?: () => Promise<LazyRoute>
594
+ lazyFn?: () => Promise<
595
+ LazyRoute<
596
+ Route<
597
+ TParentRoute,
598
+ TPath,
599
+ TFullPath,
600
+ TCustomId,
601
+ TId,
602
+ TSearchValidator,
603
+ TParams,
604
+ TRouterContext,
605
+ TRouteContextFn,
606
+ TBeforeLoadFn,
607
+ TLoaderDeps,
608
+ TLoaderFn,
609
+ TChildren,
610
+ TFileRouteTypes
611
+ >
612
+ >
613
+ >
606
614
  _lazyPromise?: Promise<void>
607
615
  rank: number
608
616
  to: TrimPathRight<TFullPath>
@@ -621,7 +629,24 @@ export interface Route<
621
629
  TBeforeLoadFn
622
630
  >,
623
631
  ) => this
624
- lazy: RouteLazyFn<this>
632
+ lazy: RouteLazyFn<
633
+ Route<
634
+ TParentRoute,
635
+ TPath,
636
+ TFullPath,
637
+ TCustomId,
638
+ TId,
639
+ TSearchValidator,
640
+ TParams,
641
+ TRouterContext,
642
+ TRouteContextFn,
643
+ TBeforeLoadFn,
644
+ TLoaderDeps,
645
+ TLoaderFn,
646
+ TChildren,
647
+ TFileRouteTypes
648
+ >
649
+ >
625
650
  addChildren: RouteAddChildrenFn<
626
651
  TParentRoute,
627
652
  TPath,
@@ -1336,7 +1361,26 @@ export class BaseRoute<
1336
1361
  children?: TChildren
1337
1362
  originalIndex?: number
1338
1363
  rank!: number
1339
- lazyFn?: () => Promise<LazyRoute>
1364
+ lazyFn?: () => Promise<
1365
+ LazyRoute<
1366
+ Route<
1367
+ TParentRoute,
1368
+ TPath,
1369
+ TFullPath,
1370
+ TCustomId,
1371
+ TId,
1372
+ TSearchValidator,
1373
+ TParams,
1374
+ TRouterContext,
1375
+ TRouteContextFn,
1376
+ TBeforeLoadFn,
1377
+ TLoaderDeps,
1378
+ TLoaderFn,
1379
+ TChildren,
1380
+ TFileRouteTypes
1381
+ >
1382
+ >
1383
+ >
1340
1384
  _lazyPromise?: Promise<void>
1341
1385
  _componentsPromise?: Promise<Array<void>>
1342
1386
 
@@ -1409,7 +1453,8 @@ export class BaseRoute<
1409
1453
  if (isRoot) {
1410
1454
  this._path = rootRouteId as TPath
1411
1455
  } else if (!this.parentRoute) {
1412
- throw new Error(
1456
+ invariant(
1457
+ false,
1413
1458
  `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,
1414
1459
  )
1415
1460
  }
@@ -1449,6 +1494,16 @@ export class BaseRoute<
1449
1494
  this._ssr = options?.ssr ?? opts.defaultSsr ?? true
1450
1495
  }
1451
1496
 
1497
+ clone = (other: typeof this) => {
1498
+ this._path = other._path
1499
+ this._id = other._id
1500
+ this._fullPath = other._fullPath
1501
+ this._to = other._to
1502
+ this._ssr = other._ssr
1503
+ this.options.getParentRoute = other.options.getParentRoute
1504
+ this.children = other.children
1505
+ }
1506
+
1452
1507
  addChildren: RouteAddChildrenFn<
1453
1508
  TParentRoute,
1454
1509
  TPath,
@@ -1562,7 +1617,24 @@ export class BaseRoute<
1562
1617
  return this
1563
1618
  }
1564
1619
 
1565
- lazy: RouteLazyFn<this> = (lazyFn) => {
1620
+ lazy: RouteLazyFn<
1621
+ Route<
1622
+ TParentRoute,
1623
+ TPath,
1624
+ TFullPath,
1625
+ TCustomId,
1626
+ TId,
1627
+ TSearchValidator,
1628
+ TParams,
1629
+ TRouterContext,
1630
+ TRouteContextFn,
1631
+ TBeforeLoadFn,
1632
+ TLoaderDeps,
1633
+ TLoaderFn,
1634
+ TChildren,
1635
+ TFileRouteTypes
1636
+ >
1637
+ > = (lazyFn) => {
1566
1638
  this.lazyFn = lazyFn
1567
1639
  return this
1568
1640
  }