@tanstack/react-router 1.22.5 → 1.22.6

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 (161) hide show
  1. package/dist/cjs/CatchBoundary.cjs +1 -2
  2. package/dist/cjs/CatchBoundary.cjs.map +1 -1
  3. package/dist/cjs/Matches.cjs +12 -18
  4. package/dist/cjs/Matches.cjs.map +1 -1
  5. package/dist/cjs/Matches.d.cts +15 -15
  6. package/dist/cjs/RouterProvider.cjs +16 -15
  7. package/dist/cjs/RouterProvider.cjs.map +1 -1
  8. package/dist/cjs/RouterProvider.d.cts +6 -6
  9. package/dist/cjs/awaited.cjs +1 -1
  10. package/dist/cjs/awaited.cjs.map +1 -1
  11. package/dist/cjs/awaited.d.cts +1 -1
  12. package/dist/cjs/defer.cjs.map +1 -1
  13. package/dist/cjs/fileRoute.cjs +1 -1
  14. package/dist/cjs/fileRoute.cjs.map +1 -1
  15. package/dist/cjs/fileRoute.d.cts +17 -17
  16. package/dist/cjs/lazyRouteComponent.cjs.map +1 -1
  17. package/dist/cjs/lazyRouteComponent.d.cts +1 -1
  18. package/dist/cjs/link.cjs +10 -11
  19. package/dist/cjs/link.cjs.map +1 -1
  20. package/dist/cjs/link.d.cts +16 -13
  21. package/dist/cjs/location.d.cts +2 -2
  22. package/dist/cjs/not-found.cjs.map +1 -1
  23. package/dist/cjs/not-found.d.cts +2 -2
  24. package/dist/cjs/path.cjs +2 -2
  25. package/dist/cjs/path.cjs.map +1 -1
  26. package/dist/cjs/path.d.cts +4 -4
  27. package/dist/cjs/qss.cjs +4 -3
  28. package/dist/cjs/qss.cjs.map +1 -1
  29. package/dist/cjs/redirects.cjs.map +1 -1
  30. package/dist/cjs/redirects.d.cts +5 -5
  31. package/dist/cjs/route.cjs.map +1 -1
  32. package/dist/cjs/route.d.cts +34 -36
  33. package/dist/cjs/routeInfo.d.cts +5 -5
  34. package/dist/cjs/router.cjs +63 -66
  35. package/dist/cjs/router.cjs.map +1 -1
  36. package/dist/cjs/router.d.cts +28 -28
  37. package/dist/cjs/routerContext.cjs +1 -1
  38. package/dist/cjs/routerContext.cjs.map +1 -1
  39. package/dist/cjs/routerContext.d.cts +1 -1
  40. package/dist/cjs/scroll-restoration.cjs +7 -9
  41. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  42. package/dist/cjs/scroll-restoration.d.cts +1 -1
  43. package/dist/cjs/searchParams.cjs +10 -12
  44. package/dist/cjs/searchParams.cjs.map +1 -1
  45. package/dist/cjs/searchParams.d.cts +1 -1
  46. package/dist/cjs/useBlocker.cjs.map +1 -1
  47. package/dist/cjs/useBlocker.d.cts +2 -2
  48. package/dist/cjs/useNavigate.cjs +1 -1
  49. package/dist/cjs/useNavigate.cjs.map +1 -1
  50. package/dist/cjs/useNavigate.d.cts +4 -4
  51. package/dist/cjs/useParams.cjs +1 -1
  52. package/dist/cjs/useParams.cjs.map +1 -1
  53. package/dist/cjs/useParams.d.cts +5 -5
  54. package/dist/cjs/useRouteContext.cjs +1 -1
  55. package/dist/cjs/useRouteContext.cjs.map +1 -1
  56. package/dist/cjs/useRouteContext.d.cts +4 -4
  57. package/dist/cjs/useRouter.cjs.map +1 -1
  58. package/dist/cjs/useRouter.d.cts +2 -2
  59. package/dist/cjs/useRouterState.cjs.map +1 -1
  60. package/dist/cjs/useRouterState.d.cts +2 -2
  61. package/dist/cjs/useSearch.cjs +1 -1
  62. package/dist/cjs/useSearch.cjs.map +1 -1
  63. package/dist/cjs/useSearch.d.cts +4 -4
  64. package/dist/cjs/utils.cjs +2 -2
  65. package/dist/cjs/utils.cjs.map +1 -1
  66. package/dist/cjs/utils.d.cts +13 -11
  67. package/dist/esm/CatchBoundary.js +1 -2
  68. package/dist/esm/CatchBoundary.js.map +1 -1
  69. package/dist/esm/Matches.d.ts +15 -15
  70. package/dist/esm/Matches.js +12 -18
  71. package/dist/esm/Matches.js.map +1 -1
  72. package/dist/esm/RouterProvider.d.ts +6 -6
  73. package/dist/esm/RouterProvider.js +16 -15
  74. package/dist/esm/RouterProvider.js.map +1 -1
  75. package/dist/esm/awaited.d.ts +1 -1
  76. package/dist/esm/awaited.js +1 -1
  77. package/dist/esm/awaited.js.map +1 -1
  78. package/dist/esm/defer.js.map +1 -1
  79. package/dist/esm/fileRoute.d.ts +17 -17
  80. package/dist/esm/fileRoute.js +1 -1
  81. package/dist/esm/fileRoute.js.map +1 -1
  82. package/dist/esm/lazyRouteComponent.d.ts +1 -1
  83. package/dist/esm/lazyRouteComponent.js.map +1 -1
  84. package/dist/esm/link.d.ts +16 -13
  85. package/dist/esm/link.js +10 -11
  86. package/dist/esm/link.js.map +1 -1
  87. package/dist/esm/location.d.ts +2 -2
  88. package/dist/esm/not-found.d.ts +2 -2
  89. package/dist/esm/not-found.js.map +1 -1
  90. package/dist/esm/path.d.ts +4 -4
  91. package/dist/esm/path.js +2 -2
  92. package/dist/esm/path.js.map +1 -1
  93. package/dist/esm/qss.js +4 -3
  94. package/dist/esm/qss.js.map +1 -1
  95. package/dist/esm/redirects.d.ts +5 -5
  96. package/dist/esm/redirects.js.map +1 -1
  97. package/dist/esm/route.d.ts +34 -36
  98. package/dist/esm/route.js.map +1 -1
  99. package/dist/esm/routeInfo.d.ts +5 -5
  100. package/dist/esm/router.d.ts +28 -28
  101. package/dist/esm/router.js +63 -66
  102. package/dist/esm/router.js.map +1 -1
  103. package/dist/esm/routerContext.d.ts +1 -1
  104. package/dist/esm/routerContext.js +1 -1
  105. package/dist/esm/routerContext.js.map +1 -1
  106. package/dist/esm/scroll-restoration.d.ts +1 -1
  107. package/dist/esm/scroll-restoration.js +7 -9
  108. package/dist/esm/scroll-restoration.js.map +1 -1
  109. package/dist/esm/searchParams.d.ts +1 -1
  110. package/dist/esm/searchParams.js +10 -12
  111. package/dist/esm/searchParams.js.map +1 -1
  112. package/dist/esm/useBlocker.d.ts +2 -2
  113. package/dist/esm/useBlocker.js.map +1 -1
  114. package/dist/esm/useNavigate.d.ts +4 -4
  115. package/dist/esm/useNavigate.js +1 -1
  116. package/dist/esm/useNavigate.js.map +1 -1
  117. package/dist/esm/useParams.d.ts +5 -5
  118. package/dist/esm/useParams.js +1 -1
  119. package/dist/esm/useParams.js.map +1 -1
  120. package/dist/esm/useRouteContext.d.ts +4 -4
  121. package/dist/esm/useRouteContext.js +1 -1
  122. package/dist/esm/useRouteContext.js.map +1 -1
  123. package/dist/esm/useRouter.d.ts +2 -2
  124. package/dist/esm/useRouter.js.map +1 -1
  125. package/dist/esm/useRouterState.d.ts +2 -2
  126. package/dist/esm/useRouterState.js.map +1 -1
  127. package/dist/esm/useSearch.d.ts +4 -4
  128. package/dist/esm/useSearch.js +1 -1
  129. package/dist/esm/useSearch.js.map +1 -1
  130. package/dist/esm/utils.d.ts +13 -11
  131. package/dist/esm/utils.js +2 -2
  132. package/dist/esm/utils.js.map +1 -1
  133. package/package.json +3 -2
  134. package/src/CatchBoundary.tsx +1 -1
  135. package/src/Matches.tsx +41 -48
  136. package/src/RouterProvider.tsx +22 -16
  137. package/src/awaited.tsx +3 -3
  138. package/src/defer.ts +1 -0
  139. package/src/fileRoute.ts +53 -53
  140. package/src/history.ts +1 -1
  141. package/src/lazyRouteComponent.tsx +2 -1
  142. package/src/link.tsx +50 -42
  143. package/src/location.ts +2 -2
  144. package/src/not-found.tsx +3 -2
  145. package/src/path.ts +8 -8
  146. package/src/qss.ts +4 -5
  147. package/src/redirects.ts +5 -5
  148. package/src/route.ts +73 -67
  149. package/src/routeInfo.ts +8 -6
  150. package/src/router.ts +150 -145
  151. package/src/routerContext.tsx +2 -2
  152. package/src/scroll-restoration.tsx +9 -12
  153. package/src/searchParams.ts +11 -13
  154. package/src/useBlocker.tsx +3 -3
  155. package/src/useNavigate.tsx +7 -5
  156. package/src/useParams.tsx +6 -6
  157. package/src/useRouteContext.ts +7 -8
  158. package/src/useRouter.tsx +2 -2
  159. package/src/useRouterState.tsx +2 -2
  160. package/src/useSearch.tsx +7 -6
  161. package/src/utils.ts +36 -24
package/src/link.tsx CHANGED
@@ -2,11 +2,17 @@ import * as React from 'react'
2
2
  import { useMatch } from './Matches'
3
3
  import { useRouterState } from './useRouterState'
4
4
  import { useRouter } from './useRouter'
5
- import { Trim } from './fileRoute'
6
- import { AnyRoute, RootSearchSchema } from './route'
7
- import { RouteByPath, RoutePaths, RoutePathsAutoComplete } from './routeInfo'
8
- import { RegisteredRouter } from './router'
9
- import {
5
+ import { deepEqual, functionalUpdate } from './utils'
6
+ import type { HistoryState } from '@tanstack/history'
7
+ import type { Trim } from './fileRoute'
8
+ import type { AnyRoute, RootSearchSchema } from './route'
9
+ import type {
10
+ RouteByPath,
11
+ RoutePaths,
12
+ RoutePathsAutoComplete,
13
+ } from './routeInfo'
14
+ import type { RegisteredRouter } from './router'
15
+ import type {
10
16
  Expand,
11
17
  IsUnion,
12
18
  MakeDifferenceOptional,
@@ -15,10 +21,7 @@ import {
15
21
  PickRequired,
16
22
  Updater,
17
23
  WithoutEmpty,
18
- deepEqual,
19
- functionalUpdate,
20
24
  } from './utils'
21
- import { HistoryState } from '@tanstack/history'
22
25
 
23
26
  export type CleanPath<T extends string> = T extends `${infer L}//${infer R}`
24
27
  ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`>
@@ -28,24 +31,24 @@ export type CleanPath<T extends string> = T extends `${infer L}//${infer R}`
28
31
  ? `/${CleanPath<L>}`
29
32
  : T
30
33
 
31
- export type Split<S, TIncludeTrailingSlash = true> = S extends unknown
32
- ? string extends S
33
- ? string[]
34
- : S extends string
35
- ? CleanPath<S> extends ''
34
+ export type Split<TValue, TIncludeTrailingSlash = true> = TValue extends unknown
35
+ ? string extends TValue
36
+ ? Array<string>
37
+ : TValue extends string
38
+ ? CleanPath<TValue> extends ''
36
39
  ? []
37
40
  : TIncludeTrailingSlash extends true
38
- ? CleanPath<S> extends `${infer T}/`
41
+ ? CleanPath<TValue> extends `${infer T}/`
39
42
  ? [...Split<T>, '/']
40
- : CleanPath<S> extends `/${infer U}`
43
+ : CleanPath<TValue> extends `/${infer U}`
41
44
  ? Split<U>
42
- : CleanPath<S> extends `${infer T}/${infer U}`
45
+ : CleanPath<TValue> extends `${infer T}/${infer U}`
43
46
  ? [...Split<T>, ...Split<U>]
44
- : [S]
45
- : CleanPath<S> extends `${infer T}/${infer U}`
47
+ : [TValue]
48
+ : CleanPath<TValue> extends `${infer T}/${infer U}`
46
49
  ? [...Split<T>, ...Split<U>]
47
- : S extends string
48
- ? [S]
50
+ : TValue extends string
51
+ ? [TValue]
49
52
  : never
50
53
  : never
51
54
  : never
@@ -58,15 +61,20 @@ export type ParsePathParams<T extends string> = keyof {
58
61
  : never]: K
59
62
  }
60
63
 
61
- export type Join<T, Delimiter extends string = '/'> = T extends []
64
+ export type Join<T, TDelimiter extends string = '/'> = T extends []
62
65
  ? ''
63
66
  : T extends [infer L extends string]
64
67
  ? L
65
- : T extends [infer L extends string, ...infer Tail extends [...string[]]]
66
- ? CleanPath<`${L}${Delimiter}${Join<Tail>}`>
68
+ : T extends [
69
+ infer L extends string,
70
+ ...infer Tail extends [...Array<string>],
71
+ ]
72
+ ? CleanPath<`${L}${TDelimiter}${Join<Tail>}`>
67
73
  : never
68
74
 
69
- export type Last<T extends any[]> = T extends [...infer _, infer L] ? L : never
75
+ export type Last<T extends Array<any>> = T extends [...infer _, infer L]
76
+ ? L
77
+ : never
70
78
 
71
79
  export type RemoveTrailingSlashes<T> = T extends `${infer R}/`
72
80
  ? RemoveTrailingSlashes<R>
@@ -85,8 +93,8 @@ export type SearchRelativePathAutoComplete<
85
93
  TTo extends string,
86
94
  TSearchPath extends string,
87
95
  TPaths,
88
- SearchedPaths = SearchPaths<TPaths, TSearchPath>,
89
- > = SearchedPaths extends string ? `${TTo}/${SearchedPaths}` : never
96
+ TSearchedPaths = SearchPaths<TPaths, TSearchPath>,
97
+ > = TSearchedPaths extends string ? `${TTo}/${TSearchedPaths}` : never
90
98
 
91
99
  export type RelativeToParentPathAutoComplete<
92
100
  TFrom extends string,
@@ -190,11 +198,11 @@ export type ToSubOptions<
190
198
  type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)
191
199
 
192
200
  type ParamVariant = 'PATH' | 'SEARCH'
193
- type ExcludeRootSearchSchema<T, Excluded = Exclude<T, RootSearchSchema>> = [
194
- Excluded,
201
+ type ExcludeRootSearchSchema<T, TExcluded = Exclude<T, RootSearchSchema>> = [
202
+ TExcluded,
195
203
  ] extends [never]
196
204
  ? {}
197
- : Excluded
205
+ : TExcluded
198
206
 
199
207
  export type ResolveRoute<
200
208
  TRouteTree extends AnyRoute,
@@ -497,15 +505,15 @@ export function useLinkProps<
497
505
 
498
506
  const handleEnter = (e: MouseEvent) => {
499
507
  if (disabled) return
500
- const target = (e.target || {}) as LinkCurrentTargetElement
508
+ const eventTarget = (e.target || {}) as LinkCurrentTargetElement
501
509
 
502
510
  if (preload) {
503
- if (target.preloadTimeout) {
511
+ if (eventTarget.preloadTimeout) {
504
512
  return
505
513
  }
506
514
 
507
- target.preloadTimeout = setTimeout(() => {
508
- target.preloadTimeout = null
515
+ eventTarget.preloadTimeout = setTimeout(() => {
516
+ eventTarget.preloadTimeout = null
509
517
  doPreload()
510
518
  }, preloadDelay)
511
519
  }
@@ -513,18 +521,18 @@ export function useLinkProps<
513
521
 
514
522
  const handleLeave = (e: MouseEvent) => {
515
523
  if (disabled) return
516
- const target = (e.target || {}) as LinkCurrentTargetElement
524
+ const eventTarget = (e.target || {}) as LinkCurrentTargetElement
517
525
 
518
- if (target.preloadTimeout) {
519
- clearTimeout(target.preloadTimeout)
520
- target.preloadTimeout = null
526
+ if (eventTarget.preloadTimeout) {
527
+ clearTimeout(eventTarget.preloadTimeout)
528
+ eventTarget.preloadTimeout = null
521
529
  }
522
530
  }
523
531
 
524
532
  const composeHandlers =
525
- (handlers: (undefined | ((e: any) => void))[]) =>
533
+ (handlers: Array<undefined | ((e: any) => void)>) =>
526
534
  (e: React.SyntheticEvent) => {
527
- if (e.persist) e.persist()
535
+ e.persist()
528
536
  handlers.filter(Boolean).forEach((handler) => {
529
537
  if (e.defaultPrevented) return
530
538
  handler!(e)
@@ -538,7 +546,7 @@ export function useLinkProps<
538
546
 
539
547
  // Get the inactive props
540
548
  const resolvedInactiveProps: React.HTMLAttributes<HTMLAnchorElement> =
541
- isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {}
549
+ isActive ? {} : functionalUpdate(inactiveProps, {})
542
550
 
543
551
  return {
544
552
  ...resolvedActiveProps,
@@ -651,7 +659,7 @@ export function createLink<const TComp>(Comp: TComp): LinkComponent<TComp> {
651
659
 
652
660
  export const Link: LinkComponent<'a'> = React.forwardRef((props: any, ref) => {
653
661
  const { _asChild, ...rest } = props
654
- const { type, ...linkProps } = useLinkProps(rest as any)
662
+ const { type, ...linkProps } = useLinkProps(rest)
655
663
 
656
664
  const children =
657
665
  typeof rest.children === 'function'
@@ -666,7 +674,7 @@ export const Link: LinkComponent<'a'> = React.forwardRef((props: any, ref) => {
666
674
  ...linkProps,
667
675
  ref,
668
676
  },
669
- children as any,
677
+ children,
670
678
  )
671
679
  }) as any
672
680
 
package/src/location.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { HistoryState } from '@tanstack/history'
2
- import { AnySearchSchema } from './route'
1
+ import type { HistoryState } from '@tanstack/history'
2
+ import type { AnySearchSchema } from './route'
3
3
 
4
4
  export interface ParsedLocation<TSearchObj extends AnySearchSchema = {}> {
5
5
  href: string
package/src/not-found.tsx CHANGED
@@ -1,8 +1,9 @@
1
+ // eslint-disable-next-line @typescript-eslint/consistent-type-imports
1
2
  import * as React from 'react'
2
3
  import { CatchBoundary } from './CatchBoundary'
3
4
  import { useRouterState } from './useRouterState'
4
- import { RegisteredRouter } from './router'
5
- import { RouteIds } from './routeInfo'
5
+ import type { RegisteredRouter } from './router'
6
+ import type { RouteIds } from './routeInfo'
6
7
 
7
8
  export type NotFoundError = {
8
9
  /**
package/src/path.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { MatchLocation } from './RouterProvider'
2
- import { AnyPathParams } from './route'
3
1
  import { last } from './utils'
2
+ import type { MatchLocation } from './RouterProvider'
3
+ import type { AnyPathParams } from './route'
4
4
 
5
5
  export interface Segment {
6
6
  type: 'pathname' | 'param' | 'wildcard'
7
7
  value: string
8
8
  }
9
9
 
10
- export function joinPaths(paths: (string | undefined)[]) {
10
+ export function joinPaths(paths: Array<string | undefined>) {
11
11
  return cleanPath(paths.filter(Boolean).join('/'))
12
12
  }
13
13
 
@@ -64,14 +64,14 @@ export function resolvePath(basepath: string, base: string, to: string) {
64
64
  return cleanPath(joined)
65
65
  }
66
66
 
67
- export function parsePathname(pathname?: string): Segment[] {
67
+ export function parsePathname(pathname?: string): Array<Segment> {
68
68
  if (!pathname) {
69
69
  return []
70
70
  }
71
71
 
72
72
  pathname = cleanPath(pathname)
73
73
 
74
- const segments: Segment[] = []
74
+ const segments: Array<Segment> = []
75
75
 
76
76
  if (pathname.slice(0, 1) === '/') {
77
77
  pathname = pathname.substring(1)
@@ -206,7 +206,7 @@ export function matchByPath(
206
206
 
207
207
  const params: Record<string, string> = {}
208
208
 
209
- let isMatch = (() => {
209
+ const isMatch = (() => {
210
210
  for (
211
211
  let i = 0;
212
212
  i < Math.max(baseSegments.length, routeSegments.length);
@@ -256,7 +256,7 @@ export function matchByPath(
256
256
  }
257
257
 
258
258
  if (routeSegment.type === 'param') {
259
- if (baseSegment?.value === '/') {
259
+ if (baseSegment.value === '/') {
260
260
  return false
261
261
  }
262
262
  if (baseSegment.value.charAt(0) !== '$') {
@@ -276,5 +276,5 @@ export function matchByPath(
276
276
  return true
277
277
  })()
278
278
 
279
- return isMatch ? (params as Record<string, string>) : undefined
279
+ return isMatch ? params : undefined
280
280
  }
package/src/qss.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  // qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.
4
4
 
5
5
  export function encode(obj, pfx?: string) {
6
- var k,
6
+ let k,
7
7
  i,
8
8
  tmp,
9
9
  str = ''
@@ -27,16 +27,15 @@ export function encode(obj, pfx?: string) {
27
27
 
28
28
  function toValue(mix) {
29
29
  if (!mix) return ''
30
- var str = decodeURIComponent(mix)
30
+ const str = decodeURIComponent(mix)
31
31
  if (str === 'false') return false
32
32
  if (str === 'true') return true
33
33
  return +str * 0 === 0 && +str + '' === str ? +str : str
34
34
  }
35
35
 
36
36
  export function decode(str, pfx?: string) {
37
- var tmp,
38
- k,
39
- out = {},
37
+ let tmp, k
38
+ const out = {},
40
39
  arr = (pfx ? str.substr(pfx.length) : str).split('&')
41
40
 
42
41
  while ((tmp = arr.shift())) {
package/src/redirects.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { PickAsRequired } from '.'
2
- import { NavigateOptions } from './link'
3
- import { AnyRoute } from './route'
4
- import { RoutePaths } from './routeInfo'
5
- import { RegisteredRouter } from './router'
1
+ import type { NavigateOptions } from './link'
2
+ import type { AnyRoute } from './route'
3
+ import type { RoutePaths } from './routeInfo'
4
+ import type { RegisteredRouter } from './router'
5
+ import type { PickAsRequired } from '.'
6
6
 
7
7
  export type AnyRedirect = Redirect<any, any, any, any, any>
8
8
 
package/src/route.ts CHANGED
@@ -1,15 +1,18 @@
1
- import * as React from 'react'
2
1
  import invariant from 'tiny-invariant'
3
- import { useLoaderData, useLoaderDeps, useMatch, RouteMatch } from './Matches'
4
- import { AnyRouteMatch } from './Matches'
5
- import { NavigateOptions, ParsePathParams, ToSubOptions } from './link'
6
- import { ParsedLocation } from './location'
2
+ import { useLoaderData, useLoaderDeps, useMatch } from './Matches'
7
3
  import { joinPaths, trimPathLeft } from './path'
8
- import { RouteById, RouteIds, RoutePaths } from './routeInfo'
9
- import { AnyRouter, RegisteredRouter } from './router'
10
4
  import { useParams } from './useParams'
11
5
  import { useSearch } from './useSearch'
12
- import {
6
+ import { notFound } from './not-found'
7
+ import { useNavigate } from './useNavigate'
8
+ import type * as React from 'react'
9
+ import type { RouteMatch } from './Matches'
10
+ import type { AnyRouteMatch } from './Matches'
11
+ import type { NavigateOptions, ParsePathParams, ToSubOptions } from './link'
12
+ import type { ParsedLocation } from './location'
13
+ import type { RouteById, RouteIds, RoutePaths } from './routeInfo'
14
+ import type { AnyRouter, RegisteredRouter } from './router'
15
+ import type {
13
16
  Assign,
14
17
  Expand,
15
18
  IsAny,
@@ -17,10 +20,9 @@ import {
17
20
  PickRequired,
18
21
  UnionToIntersection,
19
22
  } from './utils'
20
- import { BuildLocationFn, NavigateFn } from './RouterProvider'
21
- import { NotFoundError, notFound } from './not-found'
22
- import { LazyRoute } from './fileRoute'
23
- import { useNavigate } from './useNavigate'
23
+ import type { BuildLocationFn, NavigateFn } from './RouterProvider'
24
+ import type { NotFoundError } from './not-found'
25
+ import type { LazyRoute } from './fileRoute'
24
26
 
25
27
  export const rootRouteId = '__root__' as const
26
28
  export type RootRouteId = typeof rootRouteId
@@ -67,8 +69,8 @@ export type RouteOptions<
67
69
  TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
68
70
  TAllContext extends Record<string, any> = AnyContext,
69
71
  TLoaderDeps extends Record<string, any> = {},
70
- TLoaderDataReturn extends any = unknown,
71
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
72
+ TLoaderDataReturn = unknown,
73
+ TLoaderData = [TLoaderDataReturn] extends [never]
72
74
  ? undefined
73
75
  : TLoaderDataReturn,
74
76
  > = BaseRouteOptions<
@@ -113,7 +115,7 @@ export type FileBaseRouteOptions<
113
115
  TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
114
116
  TAllContext extends Record<string, any> = AnyContext,
115
117
  TLoaderDeps extends Record<string, any> = {},
116
- TLoaderDataReturn extends any = unknown,
118
+ TLoaderDataReturn = unknown,
117
119
  > = {
118
120
  validateSearch?: SearchSchemaValidator<TSearchSchemaInput, TSearchSchema>
119
121
  shouldReload?:
@@ -179,7 +181,7 @@ export type BaseRouteOptions<
179
181
  TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
180
182
  TAllContext extends Record<string, any> = AnyContext,
181
183
  TLoaderDeps extends Record<string, any> = {},
182
- TLoaderDataReturn extends any = unknown,
184
+ TLoaderDataReturn = unknown,
183
185
  > = RoutePathOptions<TCustomId, TPath> &
184
186
  FileBaseRouteOptions<
185
187
  TParentRoute,
@@ -221,7 +223,7 @@ type BeforeLoadFn<
221
223
  export type UpdatableRouteOptions<
222
224
  TAllParams extends Record<string, any>,
223
225
  TFullSearchSchema extends Record<string, any>,
224
- TLoaderData extends any,
226
+ TLoaderData,
225
227
  > = {
226
228
  // test?: (args: TAllContext) => void
227
229
  // If true, this route will be matched as case-sensitive
@@ -241,10 +243,10 @@ export type UpdatableRouteOptions<
241
243
  preloadGcTime?: number
242
244
  // Filter functions that can manipulate search params *before* they are passed to links and navigate
243
245
  // calls that match this route.
244
- preSearchFilters?: SearchFilter<TFullSearchSchema>[]
246
+ preSearchFilters?: Array<SearchFilter<TFullSearchSchema>>
245
247
  // Filter functions that can manipulate search params *after* they are passed to links and navigate
246
248
  // calls that match this route.
247
- postSearchFilters?: SearchFilter<TFullSearchSchema>[]
249
+ postSearchFilters?: Array<SearchFilter<TFullSearchSchema>>
248
250
  onError?: (err: any) => void
249
251
  // These functions are called as route matches are loaded, stick around and leave the active
250
252
  // matches
@@ -255,10 +257,10 @@ export type UpdatableRouteOptions<
255
257
  params: TAllParams
256
258
  loaderData: TLoaderData
257
259
  }) =>
258
- | JSX.IntrinsicElements['meta'][]
259
- | Promise<JSX.IntrinsicElements['meta'][]>
260
- links?: () => JSX.IntrinsicElements['link'][]
261
- scripts?: () => JSX.IntrinsicElements['script'][]
260
+ | Array<JSX.IntrinsicElements['meta']>
261
+ | Promise<Array<JSX.IntrinsicElements['meta']>>
262
+ links?: () => Array<JSX.IntrinsicElements['link']>
263
+ scripts?: () => Array<JSX.IntrinsicElements['script']>
262
264
  headers?: (ctx: {
263
265
  loaderData: TLoaderData
264
266
  }) => Promise<Record<string, string>> | Record<string, string>
@@ -281,12 +283,12 @@ export type MetaDescriptor =
281
283
  | { httpEquiv: string; content: string }
282
284
  | { 'script:ld+json': LdJsonObject }
283
285
  | { tagName: 'meta' | 'link'; [name: string]: string }
284
- | { [name: string]: unknown }
286
+ | Record<string, unknown>
285
287
 
286
288
  type LdJsonObject = { [Key in string]: LdJsonValue } & {
287
289
  [Key in string]?: LdJsonValue | undefined
288
290
  }
289
- type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[]
291
+ type LdJsonArray = Array<LdJsonValue> | ReadonlyArray<LdJsonValue>
290
292
  type LdJsonPrimitive = string | number | boolean | null
291
293
  type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray
292
294
 
@@ -325,7 +327,7 @@ export type RouteLoaderFn<
325
327
  TLoaderDeps extends Record<string, any> = {},
326
328
  TAllContext extends Record<string, any> = AnyContext,
327
329
  TRouteContext extends Record<string, any> = AnyContext,
328
- TLoaderData extends any = unknown,
330
+ TLoaderData = unknown,
329
331
  > = (
330
332
  match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext, TRouteContext>,
331
333
  ) => Promise<TLoaderData> | TLoaderData | void
@@ -348,7 +350,7 @@ export interface LoaderFnContext<
348
350
  route: Route
349
351
  }
350
352
 
351
- export type SearchFilter<T, U = T> = (prev: T) => U
353
+ export type SearchFilter<TInput, TResult = TInput> = (prev: TInput) => TResult
352
354
 
353
355
  export type ResolveId<
354
356
  TParentRoute,
@@ -414,6 +416,7 @@ export interface AnyRoute
414
416
  any
415
417
  > {}
416
418
 
419
+ // eslint-disable-next-line @typescript-eslint/naming-convention
417
420
  export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>
418
421
 
419
422
  export type ResolveAllParams<
@@ -454,7 +457,7 @@ export function getRouteApi<
454
457
  TAllParams extends AnyPathParams = TRoute['types']['allParams'],
455
458
  TAllContext extends Record<string, any> = TRoute['types']['allContext'],
456
459
  TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],
457
- TLoaderData extends any = TRoute['types']['loaderData'],
460
+ TLoaderData = TRoute['types']['loaderData'],
458
461
  >(id: TId) {
459
462
  return new RouteApi<
460
463
  TId,
@@ -477,7 +480,7 @@ export class RouteApi<
477
480
  TAllParams extends AnyPathParams = TRoute['types']['allParams'],
478
481
  TAllContext extends Record<string, any> = TRoute['types']['allContext'],
479
482
  TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],
480
- TLoaderData extends any = TRoute['types']['loaderData'],
483
+ TLoaderData = TRoute['types']['loaderData'],
481
484
  > {
482
485
  id: TId
483
486
 
@@ -590,8 +593,8 @@ export class Route<
590
593
  >,
591
594
  TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
592
595
  TLoaderDeps extends Record<string, any> = {},
593
- TLoaderDataReturn extends any = unknown,
594
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
596
+ TLoaderDataReturn = unknown,
597
+ TLoaderData = [TLoaderDataReturn] extends [never]
595
598
  ? undefined
596
599
  : TLoaderDataReturn,
597
600
  TChildren extends RouteConstraints['TChildren'] = unknown,
@@ -637,7 +640,7 @@ export class Route<
637
640
  * @deprecated Use the `createRoute` function instead.
638
641
  */
639
642
  constructor(
640
- options: RouteOptions<
643
+ options?: RouteOptions<
641
644
  TParentRoute,
642
645
  TCustomId,
643
646
  TPath,
@@ -658,6 +661,7 @@ export class Route<
658
661
  >,
659
662
  ) {
660
663
  this.options = (options as any) || {}
664
+
661
665
  this.isRoot = !options?.getParentRoute as any
662
666
  invariant(
663
667
  !((options as any)?.id && (options as any)?.path),
@@ -692,29 +696,32 @@ export class Route<
692
696
  init = (opts: { originalIndex: number }) => {
693
697
  this.originalIndex = opts.originalIndex
694
698
 
695
- const options = this.options as RouteOptions<
696
- TParentRoute,
697
- TCustomId,
698
- TPath,
699
- TSearchSchemaInput,
700
- TSearchSchema,
701
- TSearchSchemaUsed,
702
- TFullSearchSchemaInput,
703
- TFullSearchSchema,
704
- TParams,
705
- TAllParams,
706
- TRouteContextReturn,
707
- TRouteContext,
708
- TRouterContext,
709
- TAllContext,
710
- TLoaderDeps,
711
- TLoaderDataReturn,
712
- TLoaderData
713
- > &
714
- RoutePathOptionsIntersection<TCustomId, TPath>
699
+ const options = this.options as
700
+ | (RouteOptions<
701
+ TParentRoute,
702
+ TCustomId,
703
+ TPath,
704
+ TSearchSchemaInput,
705
+ TSearchSchema,
706
+ TSearchSchemaUsed,
707
+ TFullSearchSchemaInput,
708
+ TFullSearchSchema,
709
+ TParams,
710
+ TAllParams,
711
+ TRouteContextReturn,
712
+ TRouteContext,
713
+ TRouterContext,
714
+ TAllContext,
715
+ TLoaderDeps,
716
+ TLoaderDataReturn,
717
+ TLoaderData
718
+ > &
719
+ RoutePathOptionsIntersection<TCustomId, TPath>)
720
+ | undefined
715
721
 
716
722
  const isRoot = !options?.path && !options?.id
717
723
 
724
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
718
725
  this.parentRoute = this.options?.getParentRoute?.()
719
726
 
720
727
  if (isRoot) {
@@ -739,9 +746,7 @@ export class Route<
739
746
  let id = isRoot
740
747
  ? rootRouteId
741
748
  : joinPaths([
742
- (this.parentRoute.id as any) === rootRouteId
743
- ? ''
744
- : this.parentRoute.id,
749
+ this.parentRoute.id === rootRouteId ? '' : this.parentRoute.id,
745
750
  customId,
746
751
  ])
747
752
 
@@ -763,7 +768,7 @@ export class Route<
763
768
  this.to = fullPath as TrimPathRight<TFullPath>
764
769
  }
765
770
 
766
- addChildren = <TNewChildren extends AnyRoute[]>(
771
+ addChildren = <TNewChildren extends Array<AnyRoute>>(
767
772
  children: TNewChildren,
768
773
  ): Route<
769
774
  TParentRoute,
@@ -792,7 +797,7 @@ export class Route<
792
797
  return this as any
793
798
  }
794
799
 
795
- updateLoader = <TNewLoaderData extends any = unknown>(options: {
800
+ updateLoader = <TNewLoaderData = unknown>(options: {
796
801
  loader: RouteLoaderFn<
797
802
  TAllParams,
798
803
  TLoaderDeps,
@@ -839,6 +844,7 @@ export class Route<
839
844
  }
840
845
 
841
846
  useMatch = <
847
+ // eslint-disable-next-line no-shadow
842
848
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
843
849
  TRouteMatchState = RouteMatch<TRouteTree, TId>,
844
850
  TSelected = TRouteMatchState,
@@ -933,8 +939,8 @@ export function createRoute<
933
939
  >,
934
940
  TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
935
941
  TLoaderDeps extends Record<string, any> = {},
936
- TLoaderDataReturn extends any = unknown,
937
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
942
+ TLoaderDataReturn = unknown,
943
+ TLoaderData = [TLoaderDataReturn] extends [never]
938
944
  ? undefined
939
945
  : TLoaderDataReturn,
940
946
  TChildren extends RouteConstraints['TChildren'] = unknown,
@@ -997,8 +1003,8 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
997
1003
  ? RouteContext
998
1004
  : TRouteContextReturn,
999
1005
  TLoaderDeps extends Record<string, any> = {},
1000
- TLoaderDataReturn extends any = unknown,
1001
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
1006
+ TLoaderDataReturn = unknown,
1007
+ TLoaderData = [TLoaderDataReturn] extends [never]
1002
1008
  ? undefined
1003
1009
  : TLoaderDataReturn,
1004
1010
  >(
@@ -1062,8 +1068,8 @@ export class RootRoute<
1062
1068
  : TRouteContextReturn,
1063
1069
  TRouterContext extends {} = {},
1064
1070
  TLoaderDeps extends Record<string, any> = {},
1065
- TLoaderDataReturn extends any = unknown,
1066
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
1071
+ TLoaderDataReturn = unknown,
1072
+ TLoaderData = [TLoaderDataReturn] extends [never]
1067
1073
  ? undefined
1068
1074
  : TLoaderDataReturn,
1069
1075
  > extends Route<
@@ -1135,8 +1141,8 @@ export function createRootRoute<
1135
1141
  : TRouteContextReturn,
1136
1142
  TRouterContext extends {} = {},
1137
1143
  TLoaderDeps extends Record<string, any> = {},
1138
- TLoaderDataReturn extends any = unknown,
1139
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
1144
+ TLoaderDataReturn = unknown,
1145
+ TLoaderData = [TLoaderDataReturn] extends [never]
1140
1146
  ? undefined
1141
1147
  : TLoaderDataReturn,
1142
1148
  >(
@@ -1300,8 +1306,8 @@ export class NotFoundRoute<
1300
1306
  >,
1301
1307
  TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
1302
1308
  TLoaderDeps extends Record<string, any> = {},
1303
- TLoaderDataReturn extends any = unknown,
1304
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
1309
+ TLoaderDataReturn = unknown,
1310
+ TLoaderData = [TLoaderDataReturn] extends [never]
1305
1311
  ? undefined
1306
1312
  : TLoaderDataReturn,
1307
1313
  TChildren extends RouteConstraints['TChildren'] = unknown,