@tanstack/react-router 1.31.29 → 1.32.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.
Files changed (82) hide show
  1. package/dist/cjs/Matches.d.cts +6 -9
  2. package/dist/cjs/RouterProvider.d.cts +6 -6
  3. package/dist/cjs/awaited.d.cts +1 -1
  4. package/dist/cjs/defer.d.cts +1 -0
  5. package/dist/cjs/fileRoute.cjs.map +1 -1
  6. package/dist/cjs/fileRoute.d.cts +38 -79
  7. package/dist/cjs/index.cjs +2 -0
  8. package/dist/cjs/index.cjs.map +1 -1
  9. package/dist/cjs/index.d.cts +4 -3
  10. package/dist/cjs/lazyRouteComponent.d.cts +2 -1
  11. package/dist/cjs/link.cjs.map +1 -1
  12. package/dist/cjs/link.d.cts +56 -50
  13. package/dist/cjs/location.d.cts +3 -2
  14. package/dist/cjs/not-found.d.cts +2 -2
  15. package/dist/cjs/path.d.cts +3 -2
  16. package/dist/cjs/redirects.d.cts +5 -4
  17. package/dist/cjs/route.cjs +1 -1
  18. package/dist/cjs/route.cjs.map +1 -1
  19. package/dist/cjs/route.d.cts +59 -52
  20. package/dist/cjs/routeInfo.d.cts +12 -11
  21. package/dist/cjs/router.cjs +2 -2
  22. package/dist/cjs/router.cjs.map +1 -1
  23. package/dist/cjs/router.d.cts +19 -20
  24. package/dist/cjs/routerContext.d.cts +1 -1
  25. package/dist/cjs/scroll-restoration.d.cts +2 -1
  26. package/dist/cjs/searchParams.d.cts +2 -1
  27. package/dist/cjs/useBlocker.d.cts +3 -2
  28. package/dist/cjs/useLocation.cjs +10 -0
  29. package/dist/cjs/useLocation.cjs.map +1 -0
  30. package/dist/cjs/useLocation.d.cts +5 -0
  31. package/dist/cjs/useNavigate.cjs.map +1 -1
  32. package/dist/cjs/useNavigate.d.cts +5 -4
  33. package/dist/cjs/useParams.d.cts +5 -5
  34. package/dist/cjs/useRouteContext.d.cts +5 -4
  35. package/dist/cjs/useRouter.d.cts +2 -1
  36. package/dist/cjs/useRouterState.d.cts +2 -1
  37. package/dist/cjs/useSearch.d.cts +5 -4
  38. package/dist/esm/Matches.d.ts +6 -9
  39. package/dist/esm/RouterProvider.d.ts +6 -6
  40. package/dist/esm/awaited.d.ts +1 -1
  41. package/dist/esm/defer.d.ts +1 -0
  42. package/dist/esm/fileRoute.d.ts +38 -79
  43. package/dist/esm/fileRoute.js.map +1 -1
  44. package/dist/esm/index.d.ts +4 -3
  45. package/dist/esm/index.js +2 -0
  46. package/dist/esm/index.js.map +1 -1
  47. package/dist/esm/lazyRouteComponent.d.ts +2 -1
  48. package/dist/esm/link.d.ts +56 -50
  49. package/dist/esm/link.js.map +1 -1
  50. package/dist/esm/location.d.ts +3 -2
  51. package/dist/esm/not-found.d.ts +2 -2
  52. package/dist/esm/path.d.ts +3 -2
  53. package/dist/esm/redirects.d.ts +5 -4
  54. package/dist/esm/route.d.ts +59 -52
  55. package/dist/esm/route.js +1 -1
  56. package/dist/esm/route.js.map +1 -1
  57. package/dist/esm/routeInfo.d.ts +12 -11
  58. package/dist/esm/router.d.ts +19 -20
  59. package/dist/esm/router.js +2 -2
  60. package/dist/esm/router.js.map +1 -1
  61. package/dist/esm/routerContext.d.ts +1 -1
  62. package/dist/esm/scroll-restoration.d.ts +2 -1
  63. package/dist/esm/searchParams.d.ts +2 -1
  64. package/dist/esm/useBlocker.d.ts +3 -2
  65. package/dist/esm/useLocation.d.ts +5 -0
  66. package/dist/esm/useLocation.js +10 -0
  67. package/dist/esm/useLocation.js.map +1 -0
  68. package/dist/esm/useNavigate.d.ts +5 -4
  69. package/dist/esm/useNavigate.js.map +1 -1
  70. package/dist/esm/useParams.d.ts +5 -5
  71. package/dist/esm/useRouteContext.d.ts +5 -4
  72. package/dist/esm/useRouter.d.ts +2 -1
  73. package/dist/esm/useRouterState.d.ts +2 -1
  74. package/dist/esm/useSearch.d.ts +5 -4
  75. package/package.json +2 -10
  76. package/src/fileRoute.ts +26 -104
  77. package/src/index.tsx +1 -8
  78. package/src/link.tsx +205 -156
  79. package/src/route.ts +121 -106
  80. package/src/routeInfo.ts +24 -22
  81. package/src/useLocation.tsx +15 -0
  82. package/src/useNavigate.tsx +2 -2
package/src/link.tsx CHANGED
@@ -6,9 +6,11 @@ import { useRouter } from './useRouter'
6
6
  import { deepEqual, exactPathTest, functionalUpdate } from './utils'
7
7
  import type { AnyRouter, ParsedLocation } from '.'
8
8
  import type { HistoryState } from '@tanstack/history'
9
- import type { Trim } from './fileRoute'
10
9
  import type { AnyRoute, RootSearchSchema } from './route'
11
10
  import type {
11
+ CatchAllPaths,
12
+ ParseRoute,
13
+ ParseRouteWithoutBranches,
12
14
  RouteByPath,
13
15
  RouteByToPath,
14
16
  RoutePaths,
@@ -56,13 +58,16 @@ export type Split<TValue, TIncludeTrailingSlash = true> = TValue extends unknown
56
58
  : never
57
59
  : never
58
60
 
59
- export type ParsePathParams<T extends string> = keyof {
60
- [K in Trim<Split<T>[number], '_'> as K extends `$${infer L}`
61
- ? L extends ''
61
+ export type ParsePathParams<
62
+ T extends string,
63
+ TAcc = never,
64
+ > = T extends `${string}$${infer TPossiblyParam}`
65
+ ? TPossiblyParam extends `${infer TParam}/${infer TRest}`
66
+ ? ParsePathParams<TRest, TParam extends '' ? '_splat' : TParam | TAcc>
67
+ : TPossiblyParam extends ''
62
68
  ? '_splat'
63
- : L
64
- : never]: K
65
- }
69
+ : TPossiblyParam | TAcc
70
+ : TAcc
66
71
 
67
72
  export type Join<T, TDelimiter extends string = '/'> = T extends []
68
73
  ? ''
@@ -168,7 +173,9 @@ export type NavigateOptions<
168
173
  TTo extends string = '',
169
174
  TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
170
175
  TMaskTo extends string = '',
171
- > = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
176
+ > = ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & NavigateOptionProps
177
+
178
+ export interface NavigateOptionProps {
172
179
  // `replace` is a boolean that determines whether the navigation should replace the current history entry or push a new one.
173
180
  replace?: boolean
174
181
  resetScroll?: boolean
@@ -184,7 +191,13 @@ export type ToOptions<
184
191
  TTo extends string = '',
185
192
  TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
186
193
  TMaskTo extends string = '',
187
- > = ToSubOptions<TRouter, TFrom, TTo> & {
194
+ > = ToSubOptions<TRouter, TFrom, TTo> & MaskOptions<TRouter, TMaskFrom, TMaskTo>
195
+
196
+ export interface MaskOptions<
197
+ in out TRouter extends AnyRouter,
198
+ in out TMaskFrom extends RoutePaths<TRouter['routeTree']> | string,
199
+ in out TMaskTo extends string,
200
+ > {
188
201
  _fromLocation?: ParsedLocation
189
202
  mask?: ToMaskOptions<TRouter, TMaskFrom, TMaskTo>
190
203
  }
@@ -201,67 +214,95 @@ export type ToSubOptions<
201
214
  TRouter extends AnyRouter = RegisteredRouter,
202
215
  TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
203
216
  TTo extends string = '',
204
- > = {
217
+ > = ToSubOptionsProps<TRouter, TFrom, TTo> &
218
+ SearchParamOptions<TRouter, TFrom, TTo> &
219
+ PathParamOptions<TRouter, TFrom, TTo>
220
+
221
+ export interface ToSubOptionsProps<
222
+ in out TRouter extends AnyRouter = RegisteredRouter,
223
+ in out TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
224
+ in out TTo extends string = '',
225
+ > {
205
226
  to?: ToPathOption<TRouter, TFrom, TTo> & {}
206
227
  hash?: true | Updater<string>
207
228
  state?: true | NonNullableUpdater<HistoryState>
208
229
  // The source route path. This is automatically set when using route-level APIs, but for type-safe relative routing on the router itself, this is required
209
- from?: RoutePathsAutoComplete<TRouter['routeTree'], TFrom> & {}
210
- // // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path
211
- } & SearchParamOptions<TRouter, TFrom, TTo> &
212
- PathParamOptions<TRouter, TFrom, TTo>
230
+ from?: RoutePathsAutoComplete<TRouter, TFrom> & {}
231
+ }
213
232
 
214
- type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)
233
+ export type ParamsReducerFn<
234
+ in out TRouter extends AnyRouter,
235
+ in out TParamVariant extends ParamVariant,
236
+ in out TFrom,
237
+ in out TTo,
238
+ > = (
239
+ current: Expand<ResolveFromParams<TRouter, TParamVariant, TFrom>>,
240
+ ) => Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>
241
+
242
+ type ParamsReducer<
243
+ TRouter extends AnyRouter,
244
+ TParamVariant extends ParamVariant,
245
+ TFrom,
246
+ TTo,
247
+ > =
248
+ | Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>
249
+ | (ParamsReducerFn<TRouter, TParamVariant, TFrom, TTo> & {})
215
250
 
216
251
  type ParamVariant = 'PATH' | 'SEARCH'
217
252
 
218
- type ExcludeRootSearchSchema<T, TExcluded = Exclude<T, RootSearchSchema>> = [
219
- TExcluded,
220
- ] extends [never]
221
- ? {}
222
- : TExcluded
253
+ type ExcludeRootSearchSchema<T> =
254
+ Exclude<T, RootSearchSchema> extends never ? {} : Exclude<T, RootSearchSchema>
223
255
 
224
256
  export type ResolveRoute<
225
257
  TRouter extends AnyRouter,
226
258
  TFrom,
227
259
  TTo,
228
- TPath = string extends TFrom
229
- ? TTo
230
- : string extends TTo
231
- ? TFrom
232
- : ResolveRelativePath<TFrom, TTo>,
233
- > = TPath extends string
234
- ? string extends TTo
235
- ? RouteByPath<TRouter['routeTree'], TPath>
236
- : RouteByToPath<TRouter, TPath>
237
- : never
260
+ TPath = ResolveRelativePath<TFrom, TTo>,
261
+ > = string extends TPath
262
+ ? ParseRouteWithoutBranches<TRouter['routeTree']>
263
+ : TPath extends CatchAllPaths
264
+ ? ParseRouteWithoutBranches<TRouter['routeTree']>
265
+ : TPath extends string
266
+ ? string extends TTo
267
+ ? RouteByPath<TRouter['routeTree'], TPath>
268
+ : RouteByToPath<TRouter, TPath>
269
+ : never
238
270
 
239
271
  type PostProcessParams<
240
272
  T,
241
273
  TParamVariant extends ParamVariant,
242
274
  > = TParamVariant extends 'SEARCH' ? ExcludeRootSearchSchema<T> : T
243
275
 
276
+ type ResolveFromParamType<TParamVariant extends ParamVariant> =
277
+ TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema'
278
+
244
279
  type ResolveFromParams<
245
280
  TRouter extends AnyRouter,
246
281
  TParamVariant extends ParamVariant,
247
282
  TFrom,
248
- > = PostProcessParams<
249
- RouteByPath<TRouter['routeTree'], TFrom>['types'][TParamVariant extends 'PATH'
250
- ? 'allParams'
251
- : 'fullSearchSchema'],
252
- TParamVariant
253
- >
283
+ > = string extends TFrom
284
+ ? PostProcessParams<
285
+ ParseRoute<
286
+ TRouter['routeTree']
287
+ >['types'][ResolveFromParamType<TParamVariant>],
288
+ TParamVariant
289
+ >
290
+ : RouteByPath<
291
+ TRouter['routeTree'],
292
+ TFrom
293
+ >['types'][ResolveFromParamType<TParamVariant>]
294
+
295
+ type ResolveToParamType<TParamVariant extends ParamVariant> =
296
+ TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput'
254
297
 
255
- type ResolveToParams<
298
+ export type ResolveToParams<
256
299
  TRouter extends AnyRouter,
257
300
  TParamVariant extends ParamVariant,
258
301
  TFrom,
259
302
  TTo,
260
303
  TRoute extends AnyRoute = ResolveRoute<TRouter, TFrom, TTo>,
261
304
  > = PostProcessParams<
262
- TRoute['types'][TParamVariant extends 'PATH'
263
- ? 'allParams'
264
- : 'fullSearchSchemaInput'],
305
+ TRoute['types'][ResolveToParamType<TParamVariant>],
265
306
  TParamVariant
266
307
  >
267
308
 
@@ -280,67 +321,54 @@ type ResolveRelativeToParams<
280
321
  TToParams
281
322
  >
282
323
 
283
- type MakeOptionalParams<
284
- TRouter extends AnyRouter,
285
- TParamVariant extends ParamVariant,
286
- TFrom,
287
- TTo,
288
- > = TParamVariant extends 'SEARCH'
289
- ? {
290
- search?:
291
- | true
292
- | (ParamsReducer<
293
- Expand<ResolveFromParams<TRouter, TParamVariant, TFrom>>,
294
- Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>
295
- > & {})
296
- }
297
- : {
298
- params?:
299
- | true
300
- | (ParamsReducer<
301
- Expand<ResolveFromParams<TRouter, TParamVariant, TFrom>>,
302
- Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>
303
- > & {})
304
- }
324
+ interface MakeOptionalSearchParams<
325
+ in out TRouter extends AnyRouter,
326
+ in out TFrom,
327
+ in out TTo,
328
+ > {
329
+ search?: true | (ParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {})
330
+ }
331
+
332
+ interface MakeOptionalPathParams<
333
+ in out TRouter extends AnyRouter,
334
+ in out TFrom,
335
+ in out TTo,
336
+ > {
337
+ params?: true | (ParamsReducer<TRouter, 'PATH', TFrom, TTo> & {})
338
+ }
305
339
 
306
340
  type MakeRequiredParamsReducer<
307
341
  TRouter extends AnyRouter,
308
342
  TParamVariant extends ParamVariant,
309
343
  TFrom,
310
- TToParams,
311
- TFromParams = ResolveFromParams<TRouter, TParamVariant, TFrom>,
344
+ TTo,
312
345
  > =
313
- | ([TFromParams] extends [WithoutEmpty<PickRequired<TToParams>>]
314
- ? true
315
- : never)
316
- | ParamsReducer<Expand<TFromParams>, TToParams>
346
+ | (string extends TFrom
347
+ ? never
348
+ : ResolveFromParams<TRouter, TParamVariant, TFrom> extends WithoutEmpty<
349
+ PickRequired<
350
+ ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>
351
+ >
352
+ >
353
+ ? true
354
+ : never)
355
+ | (ParamsReducer<TRouter, TParamVariant, TFrom, TTo> & {})
356
+
357
+ export interface MakeRequiredPathParams<
358
+ in out TRouter extends AnyRouter,
359
+ in out TFrom,
360
+ in out TTo,
361
+ > {
362
+ params: MakeRequiredParamsReducer<TRouter, 'PATH', TFrom, TTo> & {}
363
+ }
317
364
 
318
- export type MakeRequiredParams<
319
- TRouter extends AnyRouter,
320
- TParamVariant extends ParamVariant,
321
- TFrom,
322
- TTo,
323
- > = TParamVariant extends 'SEARCH'
324
- ? {
325
- search: Expand<
326
- MakeRequiredParamsReducer<
327
- TRouter,
328
- TParamVariant,
329
- TFrom,
330
- Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>
331
- >
332
- > & {}
333
- }
334
- : {
335
- params: Expand<
336
- MakeRequiredParamsReducer<
337
- TRouter,
338
- TParamVariant,
339
- TFrom,
340
- Expand<ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>>
341
- >
342
- > & {}
343
- }
365
+ export interface MakeRequiredSearchParams<
366
+ in out TRouter extends AnyRouter,
367
+ in out TFrom,
368
+ in out TTo,
369
+ > {
370
+ search: MakeRequiredParamsReducer<TRouter, 'SEARCH', TFrom, TTo> & {}
371
+ }
344
372
 
345
373
  export type IsRequiredParams<TParams> = keyof TParams extends infer K extends
346
374
  keyof TParams
@@ -356,41 +384,36 @@ export type IsRequired<
356
384
  TParamVariant extends ParamVariant,
357
385
  TFrom,
358
386
  TTo,
359
- > = string extends TTo
360
- ? string extends TFrom
361
- ? never
362
- : IsRequiredParams<
363
- ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>
364
- >
365
- : IsRequiredParams<
366
- ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>
367
- >
368
-
369
- export type ParamOptions<
370
- TRouter extends AnyRouter,
371
- TFrom,
372
- TTo extends string,
373
- TParamVariant extends ParamVariant,
374
387
  > =
375
- IsRequired<TRouter, TParamVariant, TFrom, TTo> extends never
376
- ? MakeOptionalParams<TRouter, TParamVariant, TFrom, TTo>
377
- : MakeRequiredParams<TRouter, TParamVariant, TFrom, TTo>
388
+ string extends ResolveRelativePath<TFrom, TTo>
389
+ ? never
390
+ : ResolveRelativePath<TFrom, TTo> extends CatchAllPaths
391
+ ? never
392
+ : IsRequiredParams<
393
+ ResolveRelativeToParams<TRouter, TParamVariant, TFrom, TTo>
394
+ >
378
395
 
379
396
  export type SearchParamOptions<
380
397
  TRouter extends AnyRouter,
381
398
  TFrom,
382
399
  TTo extends string,
383
- > = ParamOptions<TRouter, TFrom, TTo, 'SEARCH'>
400
+ > =
401
+ IsRequired<TRouter, 'SEARCH', TFrom, TTo> extends never
402
+ ? MakeOptionalSearchParams<TRouter, TFrom, TTo>
403
+ : MakeRequiredSearchParams<TRouter, TFrom, TTo>
384
404
 
385
405
  export type PathParamOptions<
386
406
  TRouter extends AnyRouter,
387
407
  TFrom,
388
408
  TTo extends string,
389
- > = ParamOptions<TRouter, TFrom, TTo, 'PATH'>
409
+ > =
410
+ IsRequired<TRouter, 'PATH', TFrom, TTo> extends never
411
+ ? MakeOptionalPathParams<TRouter, TFrom, TTo>
412
+ : MakeRequiredPathParams<TRouter, TFrom, TTo>
390
413
 
391
414
  export type ToPathOption<
392
415
  TRouter extends AnyRouter = AnyRouter,
393
- TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
416
+ TFrom extends string = string,
394
417
  TTo extends string = string,
395
418
  > =
396
419
  | CheckPath<TRouter, TTo, never, TFrom, TTo>
@@ -408,11 +431,13 @@ export interface ActiveOptions {
408
431
 
409
432
  export type LinkOptions<
410
433
  TRouter extends AnyRouter = RegisteredRouter,
411
- TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
434
+ TFrom extends string = string,
412
435
  TTo extends string = '',
413
- TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
436
+ TMaskFrom extends string = TFrom,
414
437
  TMaskTo extends string = '',
415
- > = NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
438
+ > = NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & LinkOptionsProps
439
+
440
+ export interface LinkOptionsProps {
416
441
  // The standard anchor tag target attribute
417
442
  target?: HTMLAnchorElement['target']
418
443
  // Defaults to `{ exact: false, includeHash: false }`
@@ -426,31 +451,41 @@ export type LinkOptions<
426
451
  }
427
452
 
428
453
  export type CheckPath<TRouter extends AnyRouter, TPass, TFail, TFrom, TTo> =
429
- ResolveRoute<TRouter, TFrom, TTo> extends never ? TFail : TPass
430
-
431
- export type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string
432
- ? TTo extends string
433
- ? TTo extends '.'
434
- ? TFrom
435
- : TTo extends `./`
436
- ? Join<[TFrom, '/']>
437
- : TTo extends `./${infer TRest}`
438
- ? ResolveRelativePath<TFrom, TRest>
439
- : TTo extends `/${infer TRest}`
440
- ? TTo
441
- : Split<TTo> extends ['..', ...infer ToRest]
442
- ? Split<TFrom> extends [...infer FromRest, infer FromTail]
443
- ? ToRest extends ['/']
444
- ? Join<['/', ...FromRest, '/']>
445
- : ResolveRelativePath<Join<FromRest>, Join<ToRest>>
446
- : never
447
- : Split<TTo> extends ['.', ...infer ToRest]
448
- ? ToRest extends ['/']
449
- ? Join<[TFrom, '/']>
450
- : ResolveRelativePath<TFrom, Join<ToRest>>
451
- : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>>
452
- : never
453
- : never
454
+ string extends ResolveRelativePath<TFrom, TTo>
455
+ ? TPass
456
+ : ResolveRelativePath<TFrom, TTo> extends CatchAllPaths
457
+ ? TPass
458
+ : ResolveRoute<TRouter, TFrom, TTo> extends never
459
+ ? TFail
460
+ : TPass
461
+
462
+ export type ResolveRelativePath<TFrom, TTo = '.'> = string extends TFrom
463
+ ? TTo
464
+ : string extends TTo
465
+ ? TFrom
466
+ : TFrom extends string
467
+ ? TTo extends string
468
+ ? TTo extends '.'
469
+ ? TFrom
470
+ : TTo extends `./`
471
+ ? Join<[TFrom, '/']>
472
+ : TTo extends `./${infer TRest}`
473
+ ? ResolveRelativePath<TFrom, TRest>
474
+ : TTo extends `/${infer TRest}`
475
+ ? TTo
476
+ : Split<TTo> extends ['..', ...infer ToRest]
477
+ ? Split<TFrom> extends [...infer FromRest, infer FromTail]
478
+ ? ToRest extends ['/']
479
+ ? Join<['/', ...FromRest, '/']>
480
+ : ResolveRelativePath<Join<FromRest>, Join<ToRest>>
481
+ : never
482
+ : Split<TTo> extends ['.', ...infer ToRest]
483
+ ? ToRest extends ['/']
484
+ ? Join<[TFrom, '/']>
485
+ : ResolveRelativePath<TFrom, Join<ToRest>>
486
+ : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>>
487
+ : never
488
+ : never
454
489
 
455
490
  // type Test1 = ResolveRelativePath<'/', '/posts'>
456
491
  // // ^?
@@ -735,11 +770,13 @@ export type UseLinkPropsOptions<
735
770
 
736
771
  export type ActiveLinkOptions<
737
772
  TRouter extends AnyRouter = RegisteredRouter,
738
- TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
773
+ TFrom extends string = string,
739
774
  TTo extends string = '',
740
- TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
775
+ TMaskFrom extends string = TFrom,
741
776
  TMaskTo extends string = '',
742
- > = LinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
777
+ > = LinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & ActiveLinkOptionProps
778
+
779
+ export interface ActiveLinkOptionProps {
743
780
  // A function that returns additional props for the `active` state of this link. These props override other props passed to the link (`style`'s are merged, `className`'s are concatenated)
744
781
  activeProps?:
745
782
  | React.AnchorHTMLAttributes<HTMLAnchorElement>
@@ -752,11 +789,14 @@ export type ActiveLinkOptions<
752
789
 
753
790
  export type LinkProps<
754
791
  TRouter extends AnyRouter = RegisteredRouter,
755
- TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
756
- TTo extends string = string,
757
- TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
792
+ TFrom extends string = string,
793
+ TTo extends string = '',
794
+ TMaskFrom extends string = TFrom,
758
795
  TMaskTo extends string = '',
759
- > = ActiveLinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
796
+ > = ActiveLinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &
797
+ LinkPropsChildren
798
+
799
+ export interface LinkPropsChildren {
760
800
  // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns
761
801
  children?:
762
802
  | React.ReactNode
@@ -766,7 +806,7 @@ export type LinkProps<
766
806
  }) => React.ReactNode)
767
807
  }
768
808
 
769
- type LinkComponentProps<TComp> = React.PropsWithoutRef<
809
+ type LinkComponentReactProps<TComp> = React.PropsWithoutRef<
770
810
  TComp extends React.FC<infer TProps> | React.Component<infer TProps>
771
811
  ? TProps
772
812
  : TComp extends keyof JSX.IntrinsicElements
@@ -783,15 +823,24 @@ type LinkComponentProps<TComp> = React.PropsWithoutRef<
783
823
  : never
784
824
  >
785
825
 
786
- export type LinkComponent<TComp> = <
826
+ export type LinkComponentProps<
827
+ TComp,
787
828
  TRouter extends AnyRouter = RegisteredRouter,
788
- TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
829
+ TFrom extends string = string,
789
830
  TTo extends string = '',
790
- TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
831
+ TMaskFrom extends string = TFrom,
832
+ TMaskTo extends string = '',
833
+ > = LinkComponentReactProps<TComp> &
834
+ LinkProps<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>
835
+
836
+ export type LinkComponent<TComp> = <
837
+ TRouter extends RegisteredRouter = RegisteredRouter,
838
+ TFrom extends string = string,
839
+ TTo extends string = '',
840
+ TMaskFrom extends string = TFrom,
791
841
  TMaskTo extends string = '',
792
842
  >(
793
- props: LinkProps<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> &
794
- LinkComponentProps<TComp>,
843
+ props: LinkComponentProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,
795
844
  ) => React.ReactElement
796
845
 
797
846
  export function createLink<const TComp>(Comp: TComp): LinkComponent<TComp> {