@tanstack/react-router 1.20.0 → 1.20.3-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 (320) hide show
  1. package/README.md +31 -0
  2. package/dist/cjs/Asset.cjs +41 -0
  3. package/dist/cjs/Asset.cjs.map +1 -0
  4. package/dist/cjs/Asset.d.cts +2 -0
  5. package/dist/cjs/CatchBoundary.cjs +16 -12
  6. package/dist/cjs/CatchBoundary.cjs.map +1 -1
  7. package/dist/cjs/CatchBoundary.d.cts +8 -32
  8. package/dist/cjs/ClientOnly.cjs +20 -0
  9. package/dist/cjs/ClientOnly.cjs.map +1 -0
  10. package/dist/cjs/ClientOnly.d.cts +29 -0
  11. package/dist/cjs/HeadContent.cjs +155 -0
  12. package/dist/cjs/HeadContent.cjs.map +1 -0
  13. package/dist/cjs/HeadContent.d.cts +7 -0
  14. package/dist/cjs/Match.cjs +252 -0
  15. package/dist/cjs/Match.cjs.map +1 -0
  16. package/dist/cjs/Match.d.cts +8 -0
  17. package/dist/cjs/Matches.cjs +39 -287
  18. package/dist/cjs/Matches.cjs.map +1 -1
  19. package/dist/cjs/Matches.d.cts +23 -83
  20. package/dist/cjs/RouterProvider.cjs +17 -140
  21. package/dist/cjs/RouterProvider.cjs.map +1 -1
  22. package/dist/cjs/RouterProvider.d.cts +8 -27
  23. package/dist/cjs/SafeFragment.cjs +8 -0
  24. package/dist/cjs/SafeFragment.cjs.map +1 -0
  25. package/dist/cjs/SafeFragment.d.cts +1 -0
  26. package/dist/cjs/ScriptOnce.cjs +28 -0
  27. package/dist/cjs/ScriptOnce.cjs.map +1 -0
  28. package/dist/cjs/ScriptOnce.d.cts +5 -0
  29. package/dist/cjs/Scripts.cjs +51 -0
  30. package/dist/cjs/Scripts.cjs.map +1 -0
  31. package/dist/cjs/Scripts.d.cts +1 -0
  32. package/dist/cjs/ScrollRestoration.cjs +39 -0
  33. package/dist/cjs/ScrollRestoration.cjs.map +1 -0
  34. package/dist/cjs/ScrollRestoration.d.cts +14 -0
  35. package/dist/cjs/Transitioner.cjs +115 -0
  36. package/dist/cjs/Transitioner.cjs.map +1 -0
  37. package/dist/cjs/Transitioner.d.cts +1 -0
  38. package/dist/cjs/awaited.cjs +12 -65
  39. package/dist/cjs/awaited.cjs.map +1 -1
  40. package/dist/cjs/awaited.d.cts +4 -4
  41. package/dist/cjs/fileRoute.cjs +41 -15
  42. package/dist/cjs/fileRoute.cjs.map +1 -1
  43. package/dist/cjs/fileRoute.d.cts +33 -108
  44. package/dist/cjs/history.d.cts +1 -0
  45. package/dist/cjs/index.cjs +216 -73
  46. package/dist/cjs/index.cjs.map +1 -1
  47. package/dist/cjs/index.d.cts +52 -29
  48. package/dist/cjs/lazyRouteComponent.cjs +40 -29
  49. package/dist/cjs/lazyRouteComponent.cjs.map +1 -1
  50. package/dist/cjs/lazyRouteComponent.d.cts +1 -1
  51. package/dist/cjs/link.cjs +212 -106
  52. package/dist/cjs/link.cjs.map +1 -1
  53. package/dist/cjs/link.d.cts +41 -86
  54. package/dist/cjs/matchContext.cjs +27 -0
  55. package/dist/cjs/matchContext.cjs.map +1 -0
  56. package/dist/cjs/matchContext.d.cts +3 -0
  57. package/dist/cjs/not-found.cjs +9 -15
  58. package/dist/cjs/not-found.cjs.map +1 -1
  59. package/dist/cjs/not-found.d.cts +5 -22
  60. package/dist/cjs/renderRouteNotFound.cjs +22 -0
  61. package/dist/cjs/renderRouteNotFound.cjs.map +1 -0
  62. package/dist/cjs/renderRouteNotFound.d.cts +2 -0
  63. package/dist/cjs/route.cjs +110 -79
  64. package/dist/cjs/route.cjs.map +1 -1
  65. package/dist/cjs/route.d.cts +64 -361
  66. package/dist/cjs/router.cjs +12 -1237
  67. package/dist/cjs/router.cjs.map +1 -1
  68. package/dist/cjs/router.d.cts +69 -237
  69. package/dist/cjs/routerContext.cjs +1 -1
  70. package/dist/cjs/routerContext.cjs.map +1 -1
  71. package/dist/cjs/routerContext.d.cts +7 -2
  72. package/dist/cjs/scroll-restoration.cjs +16 -177
  73. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  74. package/dist/cjs/scroll-restoration.d.cts +1 -18
  75. package/dist/cjs/serializer.d.cts +6 -0
  76. package/dist/cjs/structuralSharing.d.cts +8 -0
  77. package/dist/cjs/typePrimitives.d.cts +16 -0
  78. package/dist/cjs/useBlocker.cjs +138 -9
  79. package/dist/cjs/useBlocker.cjs.map +1 -1
  80. package/dist/cjs/useBlocker.d.cts +64 -7
  81. package/dist/cjs/useCanGoBack.cjs +8 -0
  82. package/dist/cjs/useCanGoBack.cjs.map +1 -0
  83. package/dist/cjs/useCanGoBack.d.cts +1 -0
  84. package/dist/cjs/useLoaderData.cjs +15 -0
  85. package/dist/cjs/useLoaderData.cjs.map +1 -0
  86. package/dist/cjs/useLoaderData.d.cts +8 -0
  87. package/dist/cjs/useLoaderDeps.cjs +14 -0
  88. package/dist/cjs/useLoaderDeps.cjs.map +1 -0
  89. package/dist/cjs/useLoaderDeps.d.cts +8 -0
  90. package/dist/cjs/useLocation.cjs +10 -0
  91. package/dist/cjs/useLocation.cjs.map +1 -0
  92. package/dist/cjs/useLocation.d.cts +7 -0
  93. package/dist/cjs/useMatch.cjs +47 -0
  94. package/dist/cjs/useMatch.cjs.map +1 -0
  95. package/dist/cjs/useMatch.d.cts +10 -0
  96. package/dist/cjs/useNavigate.cjs +18 -19
  97. package/dist/cjs/useNavigate.cjs.map +1 -1
  98. package/dist/cjs/useNavigate.d.cts +4 -8
  99. package/dist/cjs/useParams.cjs +8 -8
  100. package/dist/cjs/useParams.cjs.map +1 -1
  101. package/dist/cjs/useParams.d.cts +9 -8
  102. package/dist/cjs/useRouteContext.cjs +3 -3
  103. package/dist/cjs/useRouteContext.cjs.map +1 -1
  104. package/dist/cjs/useRouteContext.d.cts +3 -7
  105. package/dist/cjs/useRouter.cjs.map +1 -1
  106. package/dist/cjs/useRouter.d.cts +3 -4
  107. package/dist/cjs/useRouterState.cjs +18 -1
  108. package/dist/cjs/useRouterState.cjs.map +1 -1
  109. package/dist/cjs/useRouterState.d.cts +8 -6
  110. package/dist/cjs/useSearch.cjs +7 -4
  111. package/dist/cjs/useSearch.cjs.map +1 -1
  112. package/dist/cjs/useSearch.d.cts +9 -7
  113. package/dist/cjs/utils.cjs +40 -122
  114. package/dist/cjs/utils.cjs.map +1 -1
  115. package/dist/cjs/utils.d.cts +46 -50
  116. package/dist/esm/Asset.d.ts +2 -0
  117. package/dist/esm/Asset.js +41 -0
  118. package/dist/esm/Asset.js.map +1 -0
  119. package/dist/esm/CatchBoundary.d.ts +8 -32
  120. package/dist/esm/CatchBoundary.js +16 -12
  121. package/dist/esm/CatchBoundary.js.map +1 -1
  122. package/dist/esm/ClientOnly.d.ts +29 -0
  123. package/dist/esm/ClientOnly.js +20 -0
  124. package/dist/esm/ClientOnly.js.map +1 -0
  125. package/dist/esm/HeadContent.d.ts +7 -0
  126. package/dist/esm/HeadContent.js +139 -0
  127. package/dist/esm/HeadContent.js.map +1 -0
  128. package/dist/esm/Match.d.ts +8 -0
  129. package/dist/esm/Match.js +235 -0
  130. package/dist/esm/Match.js.map +1 -0
  131. package/dist/esm/Matches.d.ts +23 -83
  132. package/dist/esm/Matches.js +36 -284
  133. package/dist/esm/Matches.js.map +1 -1
  134. package/dist/esm/RouterProvider.d.ts +8 -27
  135. package/dist/esm/RouterProvider.js +20 -126
  136. package/dist/esm/RouterProvider.js.map +1 -1
  137. package/dist/esm/SafeFragment.d.ts +1 -0
  138. package/dist/esm/SafeFragment.js +8 -0
  139. package/dist/esm/SafeFragment.js.map +1 -0
  140. package/dist/esm/ScriptOnce.d.ts +5 -0
  141. package/dist/esm/ScriptOnce.js +28 -0
  142. package/dist/esm/ScriptOnce.js.map +1 -0
  143. package/dist/esm/Scripts.d.ts +1 -0
  144. package/dist/esm/Scripts.js +51 -0
  145. package/dist/esm/Scripts.js.map +1 -0
  146. package/dist/esm/ScrollRestoration.d.ts +14 -0
  147. package/dist/esm/ScrollRestoration.js +39 -0
  148. package/dist/esm/ScrollRestoration.js.map +1 -0
  149. package/dist/esm/Transitioner.d.ts +1 -0
  150. package/dist/esm/Transitioner.js +98 -0
  151. package/dist/esm/Transitioner.js.map +1 -0
  152. package/dist/esm/awaited.d.ts +4 -4
  153. package/dist/esm/awaited.js +12 -65
  154. package/dist/esm/awaited.js.map +1 -1
  155. package/dist/esm/fileRoute.d.ts +33 -108
  156. package/dist/esm/fileRoute.js +38 -12
  157. package/dist/esm/fileRoute.js.map +1 -1
  158. package/dist/esm/history.d.ts +1 -0
  159. package/dist/esm/index.d.ts +52 -29
  160. package/dist/esm/index.js +41 -29
  161. package/dist/esm/index.js.map +1 -1
  162. package/dist/esm/lazyRouteComponent.d.ts +1 -1
  163. package/dist/esm/lazyRouteComponent.js +40 -29
  164. package/dist/esm/lazyRouteComponent.js.map +1 -1
  165. package/dist/esm/link.d.ts +41 -86
  166. package/dist/esm/link.js +212 -106
  167. package/dist/esm/link.js.map +1 -1
  168. package/dist/esm/matchContext.d.ts +3 -0
  169. package/dist/esm/matchContext.js +10 -0
  170. package/dist/esm/matchContext.js.map +1 -0
  171. package/dist/esm/not-found.d.ts +5 -22
  172. package/dist/esm/not-found.js +9 -15
  173. package/dist/esm/not-found.js.map +1 -1
  174. package/dist/esm/renderRouteNotFound.d.ts +2 -0
  175. package/dist/esm/renderRouteNotFound.js +22 -0
  176. package/dist/esm/renderRouteNotFound.js.map +1 -0
  177. package/dist/esm/route.d.ts +64 -361
  178. package/dist/esm/route.js +103 -72
  179. package/dist/esm/route.js.map +1 -1
  180. package/dist/esm/router.d.ts +69 -237
  181. package/dist/esm/router.js +13 -1238
  182. package/dist/esm/router.js.map +1 -1
  183. package/dist/esm/routerContext.d.ts +7 -2
  184. package/dist/esm/routerContext.js +1 -1
  185. package/dist/esm/routerContext.js.map +1 -1
  186. package/dist/esm/scroll-restoration.d.ts +1 -18
  187. package/dist/esm/scroll-restoration.js +17 -161
  188. package/dist/esm/scroll-restoration.js.map +1 -1
  189. package/dist/esm/serializer.d.ts +6 -0
  190. package/dist/esm/structuralSharing.d.ts +8 -0
  191. package/dist/esm/typePrimitives.d.ts +16 -0
  192. package/dist/esm/useBlocker.d.ts +64 -7
  193. package/dist/esm/useBlocker.js +138 -9
  194. package/dist/esm/useBlocker.js.map +1 -1
  195. package/dist/esm/useCanGoBack.d.ts +1 -0
  196. package/dist/esm/useCanGoBack.js +8 -0
  197. package/dist/esm/useCanGoBack.js.map +1 -0
  198. package/dist/esm/useLoaderData.d.ts +8 -0
  199. package/dist/esm/useLoaderData.js +15 -0
  200. package/dist/esm/useLoaderData.js.map +1 -0
  201. package/dist/esm/useLoaderDeps.d.ts +8 -0
  202. package/dist/esm/useLoaderDeps.js +14 -0
  203. package/dist/esm/useLoaderDeps.js.map +1 -0
  204. package/dist/esm/useLocation.d.ts +7 -0
  205. package/dist/esm/useLocation.js +10 -0
  206. package/dist/esm/useLocation.js.map +1 -0
  207. package/dist/esm/useMatch.d.ts +10 -0
  208. package/dist/esm/useMatch.js +30 -0
  209. package/dist/esm/useMatch.js.map +1 -0
  210. package/dist/esm/useNavigate.d.ts +4 -8
  211. package/dist/esm/useNavigate.js +18 -19
  212. package/dist/esm/useNavigate.js.map +1 -1
  213. package/dist/esm/useParams.d.ts +9 -8
  214. package/dist/esm/useParams.js +8 -8
  215. package/dist/esm/useParams.js.map +1 -1
  216. package/dist/esm/useRouteContext.d.ts +3 -7
  217. package/dist/esm/useRouteContext.js +2 -2
  218. package/dist/esm/useRouteContext.js.map +1 -1
  219. package/dist/esm/useRouter.d.ts +3 -4
  220. package/dist/esm/useRouter.js.map +1 -1
  221. package/dist/esm/useRouterState.d.ts +8 -6
  222. package/dist/esm/useRouterState.js +18 -1
  223. package/dist/esm/useRouterState.js.map +1 -1
  224. package/dist/esm/useSearch.d.ts +9 -7
  225. package/dist/esm/useSearch.js +6 -3
  226. package/dist/esm/useSearch.js.map +1 -1
  227. package/dist/esm/utils.d.ts +46 -50
  228. package/dist/esm/utils.js +41 -123
  229. package/dist/esm/utils.js.map +1 -1
  230. package/package.json +30 -31
  231. package/src/Asset.tsx +40 -0
  232. package/src/CatchBoundary.tsx +35 -19
  233. package/src/ClientOnly.tsx +68 -0
  234. package/src/HeadContent.tsx +174 -0
  235. package/src/Match.tsx +330 -0
  236. package/src/Matches.tsx +149 -558
  237. package/src/RouterProvider.tsx +58 -212
  238. package/src/SafeFragment.tsx +5 -0
  239. package/src/ScriptOnce.tsx +32 -0
  240. package/src/Scripts.tsx +65 -0
  241. package/src/ScrollRestoration.tsx +69 -0
  242. package/src/Transitioner.tsx +130 -0
  243. package/src/awaited.tsx +16 -87
  244. package/src/fileRoute.ts +145 -248
  245. package/src/history.ts +2 -1
  246. package/src/index.tsx +368 -30
  247. package/src/lazyRouteComponent.tsx +68 -54
  248. package/src/link.tsx +397 -522
  249. package/src/matchContext.tsx +8 -0
  250. package/src/not-found.tsx +13 -34
  251. package/src/renderRouteNotFound.tsx +27 -0
  252. package/src/route.tsx +572 -0
  253. package/src/router.ts +99 -2067
  254. package/src/routerContext.tsx +8 -2
  255. package/src/scroll-restoration.tsx +23 -224
  256. package/src/serializer.ts +7 -0
  257. package/src/structuralSharing.ts +47 -0
  258. package/src/typePrimitives.ts +84 -0
  259. package/src/useBlocker.tsx +297 -15
  260. package/src/useCanGoBack.ts +5 -0
  261. package/src/useLoaderData.tsx +80 -0
  262. package/src/useLoaderDeps.tsx +58 -0
  263. package/src/useLocation.tsx +41 -0
  264. package/src/useMatch.tsx +119 -0
  265. package/src/useNavigate.tsx +41 -61
  266. package/src/useParams.tsx +88 -23
  267. package/src/useRouteContext.ts +24 -18
  268. package/src/useRouter.tsx +4 -5
  269. package/src/useRouterState.tsx +52 -10
  270. package/src/useSearch.tsx +87 -24
  271. package/src/utils.ts +97 -312
  272. package/dist/cjs/createServerFn.cjs +0 -40
  273. package/dist/cjs/createServerFn.cjs.map +0 -1
  274. package/dist/cjs/createServerFn.d.cts +0 -44
  275. package/dist/cjs/defer.cjs +0 -30
  276. package/dist/cjs/defer.cjs.map +0 -1
  277. package/dist/cjs/defer.d.cts +0 -25
  278. package/dist/cjs/location.d.cts +0 -12
  279. package/dist/cjs/path.cjs +0 -213
  280. package/dist/cjs/path.cjs.map +0 -1
  281. package/dist/cjs/path.d.cts +0 -24
  282. package/dist/cjs/qss.cjs +0 -45
  283. package/dist/cjs/qss.cjs.map +0 -1
  284. package/dist/cjs/qss.d.cts +0 -2
  285. package/dist/cjs/redirects.cjs +0 -16
  286. package/dist/cjs/redirects.cjs.map +0 -1
  287. package/dist/cjs/redirects.d.cts +0 -18
  288. package/dist/cjs/routeInfo.d.cts +0 -33
  289. package/dist/cjs/searchParams.cjs +0 -63
  290. package/dist/cjs/searchParams.cjs.map +0 -1
  291. package/dist/cjs/searchParams.d.cts +0 -7
  292. package/dist/esm/createServerFn.d.ts +0 -44
  293. package/dist/esm/createServerFn.js +0 -40
  294. package/dist/esm/createServerFn.js.map +0 -1
  295. package/dist/esm/defer.d.ts +0 -25
  296. package/dist/esm/defer.js +0 -30
  297. package/dist/esm/defer.js.map +0 -1
  298. package/dist/esm/location.d.ts +0 -12
  299. package/dist/esm/path.d.ts +0 -24
  300. package/dist/esm/path.js +0 -213
  301. package/dist/esm/path.js.map +0 -1
  302. package/dist/esm/qss.d.ts +0 -2
  303. package/dist/esm/qss.js +0 -45
  304. package/dist/esm/qss.js.map +0 -1
  305. package/dist/esm/redirects.d.ts +0 -18
  306. package/dist/esm/redirects.js +0 -16
  307. package/dist/esm/redirects.js.map +0 -1
  308. package/dist/esm/routeInfo.d.ts +0 -33
  309. package/dist/esm/searchParams.d.ts +0 -7
  310. package/dist/esm/searchParams.js +0 -63
  311. package/dist/esm/searchParams.js.map +0 -1
  312. package/src/createServerFn.ts +0 -107
  313. package/src/defer.ts +0 -70
  314. package/src/location.ts +0 -13
  315. package/src/path.ts +0 -280
  316. package/src/qss.ts +0 -53
  317. package/src/redirects.ts +0 -56
  318. package/src/route.ts +0 -1356
  319. package/src/routeInfo.ts +0 -62
  320. package/src/searchParams.ts +0 -79
package/src/route.ts DELETED
@@ -1,1356 +0,0 @@
1
- import * as React from 'react'
2
- 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'
7
- import { joinPaths, trimPathLeft } from './path'
8
- import { RouteById, RouteIds, RoutePaths } from './routeInfo'
9
- import { AnyRouter, RegisteredRouter } from './router'
10
- import { useParams } from './useParams'
11
- import { useSearch } from './useSearch'
12
- import {
13
- Assign,
14
- Expand,
15
- IsAny,
16
- NoInfer,
17
- PickRequired,
18
- UnionToIntersection,
19
- } from './utils'
20
- import { BuildLocationFn, NavigateFn } from './RouterProvider'
21
- import { NotFoundError, notFound } from './not-found'
22
- import { LazyRoute } from './fileRoute'
23
-
24
- export const rootRouteId = '__root__' as const
25
- export type RootRouteId = typeof rootRouteId
26
- export type AnyPathParams = {}
27
-
28
- export type SearchSchemaInput = {
29
- __TSearchSchemaInput__: 'TSearchSchemaInput'
30
- }
31
-
32
- export type AnySearchSchema = {}
33
-
34
- export type AnyContext = {}
35
-
36
- export interface RouteContext {}
37
-
38
- export type PreloadableObj = { preload?: () => Promise<void> }
39
-
40
- export type RoutePathOptions<TCustomId, TPath> =
41
- | {
42
- path: TPath
43
- }
44
- | {
45
- id: TCustomId
46
- }
47
-
48
- export interface StaticDataRouteOption {}
49
-
50
- export type RoutePathOptionsIntersection<TCustomId, TPath> =
51
- UnionToIntersection<RoutePathOptions<TCustomId, TPath>>
52
-
53
- export type RouteOptions<
54
- TParentRoute extends AnyRoute = AnyRoute,
55
- TCustomId extends string = string,
56
- TPath extends string = string,
57
- TSearchSchemaInput extends Record<string, any> = {},
58
- TSearchSchema extends Record<string, any> = {},
59
- TSearchSchemaUsed extends Record<string, any> = {},
60
- TFullSearchSchemaInput extends Record<string, any> = TSearchSchemaUsed,
61
- TFullSearchSchema extends Record<string, any> = TSearchSchema,
62
- TParams extends AnyPathParams = AnyPathParams,
63
- TAllParams extends AnyPathParams = TParams,
64
- TRouteContextReturn extends RouteContext = RouteContext,
65
- TRouteContext extends RouteContext = RouteContext,
66
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
67
- TAllContext extends Record<string, any> = AnyContext,
68
- TLoaderDeps extends Record<string, any> = {},
69
- TLoaderDataReturn extends any = unknown,
70
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
71
- ? undefined
72
- : TLoaderDataReturn,
73
- > = BaseRouteOptions<
74
- TParentRoute,
75
- TCustomId,
76
- TPath,
77
- TSearchSchemaInput,
78
- TSearchSchema,
79
- TSearchSchemaUsed,
80
- TFullSearchSchemaInput,
81
- TFullSearchSchema,
82
- TParams,
83
- TAllParams,
84
- TRouteContextReturn,
85
- TRouteContext,
86
- TRouterContext,
87
- TAllContext,
88
- TLoaderDeps,
89
- TLoaderDataReturn
90
- > &
91
- UpdatableRouteOptions<
92
- NoInfer<TAllParams>,
93
- NoInfer<TFullSearchSchema>,
94
- NoInfer<TLoaderData>
95
- >
96
-
97
- export type ParamsFallback<
98
- TPath extends string,
99
- TParams,
100
- > = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams
101
-
102
- export type FileBaseRouteOptions<
103
- TParentRoute extends AnyRoute = AnyRoute,
104
- TPath extends string = string,
105
- TSearchSchemaInput extends Record<string, any> = {},
106
- TSearchSchema extends Record<string, any> = {},
107
- TFullSearchSchema extends Record<string, any> = TSearchSchema,
108
- TParams extends AnyPathParams = {},
109
- TAllParams = ParamsFallback<TPath, TParams>,
110
- TRouteContextReturn extends RouteContext = RouteContext,
111
- TRouteContext extends RouteContext = RouteContext,
112
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
113
- TAllContext extends Record<string, any> = AnyContext,
114
- TLoaderDeps extends Record<string, any> = {},
115
- TLoaderDataReturn extends any = unknown,
116
- > = {
117
- validateSearch?: SearchSchemaValidator<TSearchSchemaInput, TSearchSchema>
118
- shouldReload?:
119
- | boolean
120
- | ((
121
- match: LoaderFnContext<
122
- TAllParams,
123
- TFullSearchSchema,
124
- TAllContext,
125
- TRouteContext
126
- >,
127
- ) => any)
128
- // This async function is called before a route is loaded.
129
- // If an error is thrown here, the route's loader will not be called.
130
- // If thrown during a navigation, the navigation will be cancelled and the error will be passed to the `onError` function.
131
- // If thrown during a preload event, the error will be logged to the console.
132
- beforeLoad?: BeforeLoadFn<
133
- TFullSearchSchema,
134
- TParentRoute,
135
- TAllParams,
136
- TRouteContextReturn,
137
- TRouterContext
138
- >
139
- loaderDeps?: (opts: { search: TFullSearchSchema }) => TLoaderDeps
140
- loader?: RouteLoaderFn<
141
- TAllParams,
142
- NoInfer<TLoaderDeps>,
143
- NoInfer<TAllContext>,
144
- NoInfer<TRouteContext>,
145
- TLoaderDataReturn
146
- >
147
- } & (
148
- | {
149
- // Both or none
150
- parseParams?: (
151
- rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,
152
- ) => TParams extends Record<ParsePathParams<TPath>, any>
153
- ? TParams
154
- : 'parseParams must return an object'
155
- stringifyParams?: (
156
- params: NoInfer<ParamsFallback<TPath, TParams>>,
157
- ) => Record<ParsePathParams<TPath>, string>
158
- }
159
- | {
160
- stringifyParams?: never
161
- parseParams?: never
162
- }
163
- )
164
-
165
- export type BaseRouteOptions<
166
- TParentRoute extends AnyRoute = AnyRoute,
167
- TCustomId extends string = string,
168
- TPath extends string = string,
169
- TSearchSchemaInput extends Record<string, any> = {},
170
- TSearchSchema extends Record<string, any> = {},
171
- TSearchSchemaUsed extends Record<string, any> = {},
172
- TFullSearchSchemaInput extends Record<string, any> = TSearchSchemaUsed,
173
- TFullSearchSchema extends Record<string, any> = TSearchSchema,
174
- TParams extends AnyPathParams = {},
175
- TAllParams = ParamsFallback<TPath, TParams>,
176
- TRouteContextReturn extends RouteContext = RouteContext,
177
- TRouteContext extends RouteContext = RouteContext,
178
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
179
- TAllContext extends Record<string, any> = AnyContext,
180
- TLoaderDeps extends Record<string, any> = {},
181
- TLoaderDataReturn extends any = unknown,
182
- > = RoutePathOptions<TCustomId, TPath> &
183
- FileBaseRouteOptions<
184
- TParentRoute,
185
- TPath,
186
- TSearchSchemaInput,
187
- TSearchSchema,
188
- TFullSearchSchema,
189
- TParams,
190
- TAllParams,
191
- TRouteContextReturn,
192
- TRouteContext,
193
- TRouterContext,
194
- TAllContext,
195
- TLoaderDeps,
196
- TLoaderDataReturn
197
- > & {
198
- getParentRoute: () => TParentRoute
199
- }
200
-
201
- type BeforeLoadFn<
202
- TFullSearchSchema extends Record<string, any>,
203
- TParentRoute extends AnyRoute,
204
- TAllParams,
205
- TRouteContextReturn extends RouteContext,
206
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
207
- TContext = IsAny<TParentRoute['types']['allContext'], TRouterContext>,
208
- > = (opts: {
209
- search: TFullSearchSchema
210
- abortController: AbortController
211
- preload: boolean
212
- params: TAllParams
213
- context: TContext
214
- location: ParsedLocation
215
- navigate: NavigateFn
216
- buildLocation: BuildLocationFn<TParentRoute>
217
- cause: 'preload' | 'enter' | 'stay'
218
- }) => Promise<TRouteContextReturn> | TRouteContextReturn | void
219
-
220
- export type UpdatableRouteOptions<
221
- TAllParams extends Record<string, any>,
222
- TFullSearchSchema extends Record<string, any>,
223
- TLoaderData extends any,
224
- > = {
225
- // test?: (args: TAllContext) => void
226
- // If true, this route will be matched as case-sensitive
227
- caseSensitive?: boolean
228
- // If true, this route will be forcefully wrapped in a suspense boundary
229
- wrapInSuspense?: boolean
230
- // The content to be rendered when the route is matched. If no component is provided, defaults to `<Outlet />`
231
- component?: RouteComponent
232
- errorComponent?: false | null | ErrorRouteComponent
233
- notFoundComponent?: NotFoundRouteComponent
234
- pendingComponent?: RouteComponent
235
- pendingMs?: number
236
- pendingMinMs?: number
237
- staleTime?: number
238
- gcTime?: number
239
- preloadStaleTime?: number
240
- preloadGcTime?: number
241
- // Filter functions that can manipulate search params *before* they are passed to links and navigate
242
- // calls that match this route.
243
- preSearchFilters?: SearchFilter<TFullSearchSchema>[]
244
- // Filter functions that can manipulate search params *after* they are passed to links and navigate
245
- // calls that match this route.
246
- postSearchFilters?: SearchFilter<TFullSearchSchema>[]
247
- onError?: (err: any) => void
248
- // These functions are called as route matches are loaded, stick around and leave the active
249
- // matches
250
- onEnter?: (match: AnyRouteMatch) => void
251
- onStay?: (match: AnyRouteMatch) => void
252
- onLeave?: (match: AnyRouteMatch) => void
253
- meta?: (ctx: {
254
- params: TAllParams
255
- loaderData: TLoaderData
256
- }) =>
257
- | JSX.IntrinsicElements['meta'][]
258
- | Promise<JSX.IntrinsicElements['meta'][]>
259
- links?: () => JSX.IntrinsicElements['link'][]
260
- scripts?: () => JSX.IntrinsicElements['script'][]
261
- headers?: (ctx: {
262
- loaderData: TLoaderData
263
- }) => Promise<Record<string, string>> | Record<string, string>
264
- } & UpdatableStaticRouteOption
265
-
266
- export type UpdatableStaticRouteOption =
267
- {} extends PickRequired<StaticDataRouteOption>
268
- ? {
269
- staticData?: StaticDataRouteOption
270
- }
271
- : {
272
- staticData: StaticDataRouteOption
273
- }
274
-
275
- export type MetaDescriptor =
276
- | { charSet: 'utf-8' }
277
- | { title: string }
278
- | { name: string; content: string }
279
- | { property: string; content: string }
280
- | { httpEquiv: string; content: string }
281
- | { 'script:ld+json': LdJsonObject }
282
- | { tagName: 'meta' | 'link'; [name: string]: string }
283
- | { [name: string]: unknown }
284
-
285
- type LdJsonObject = { [Key in string]: LdJsonValue } & {
286
- [Key in string]?: LdJsonValue | undefined
287
- }
288
- type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[]
289
- type LdJsonPrimitive = string | number | boolean | null
290
- type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray
291
-
292
- export type RouteLinkEntry = {}
293
-
294
- export type ParseParamsOption<TPath extends string, TParams> = ParseParamsFn<
295
- TPath,
296
- TParams
297
- >
298
-
299
- export type ParseParamsFn<TPath extends string, TParams> = (
300
- rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,
301
- ) => TParams extends Record<ParsePathParams<TPath>, any>
302
- ? TParams
303
- : 'parseParams must return an object'
304
-
305
- export type ParseParamsObj<TPath extends string, TParams> = {
306
- parse?: ParseParamsFn<TPath, TParams>
307
- }
308
-
309
- // The parse type here allows a zod schema to be passed directly to the validator
310
- export type SearchSchemaValidator<TInput, TReturn> =
311
- | SearchSchemaValidatorObj<TInput, TReturn>
312
- | SearchSchemaValidatorFn<TInput, TReturn>
313
-
314
- export type SearchSchemaValidatorObj<TInput, TReturn> = {
315
- parse?: SearchSchemaValidatorFn<TInput, TReturn>
316
- }
317
-
318
- export type SearchSchemaValidatorFn<TInput, TReturn> = (
319
- searchObj: TInput,
320
- ) => TReturn
321
-
322
- export type RouteLoaderFn<
323
- TAllParams = {},
324
- TLoaderDeps extends Record<string, any> = {},
325
- TAllContext extends Record<string, any> = AnyContext,
326
- TRouteContext extends Record<string, any> = AnyContext,
327
- TLoaderData extends any = unknown,
328
- > = (
329
- match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext, TRouteContext>,
330
- ) => Promise<TLoaderData> | TLoaderData | void
331
-
332
- export interface LoaderFnContext<
333
- TAllParams = {},
334
- TLoaderDeps extends Record<string, any> = {},
335
- TAllContext extends Record<string, any> = AnyContext,
336
- TRouteContext extends Record<string, any> = AnyContext,
337
- > {
338
- abortController: AbortController
339
- preload: boolean
340
- params: TAllParams
341
- deps: TLoaderDeps
342
- context: Expand<Assign<TAllContext, TRouteContext>>
343
- location: ParsedLocation // Do not supply search schema here so as to demotivate people from trying to shortcut loaderDeps
344
- navigate: (opts: NavigateOptions<AnyRoute>) => Promise<void>
345
- parentMatchPromise?: Promise<void>
346
- cause: 'preload' | 'enter' | 'stay'
347
- route: Route
348
- }
349
-
350
- export type SearchFilter<T, U = T> = (prev: T) => U
351
-
352
- export type ResolveId<
353
- TParentRoute,
354
- TCustomId extends string,
355
- TPath extends string,
356
- > = TParentRoute extends { id: infer TParentId extends string }
357
- ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId>
358
- : RootRouteId
359
-
360
- export type InferFullSearchSchema<TRoute> = TRoute extends {
361
- types: {
362
- fullSearchSchema: infer TFullSearchSchema
363
- }
364
- }
365
- ? TFullSearchSchema
366
- : {}
367
-
368
- export type InferFullSearchSchemaInput<TRoute> = TRoute extends {
369
- types: {
370
- fullSearchSchemaInput: infer TFullSearchSchemaInput
371
- }
372
- }
373
- ? TFullSearchSchemaInput
374
- : {}
375
-
376
- export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<
377
- Assign<
378
- Omit<InferFullSearchSchema<TParentRoute>, keyof RootSearchSchema>,
379
- TSearchSchema
380
- >
381
- >
382
-
383
- export type ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed> =
384
- Expand<
385
- Assign<
386
- Omit<InferFullSearchSchemaInput<TParentRoute>, keyof RootSearchSchema>,
387
- TSearchSchemaUsed
388
- >
389
- >
390
-
391
- export interface AnyRoute
392
- extends Route<
393
- any,
394
- any,
395
- any,
396
- any,
397
- any,
398
- any,
399
- any,
400
- any,
401
- any,
402
- any,
403
- any,
404
- any,
405
- any,
406
- any,
407
- any,
408
- any,
409
- any,
410
- any,
411
- any,
412
- any,
413
- any
414
- > {}
415
-
416
- export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>
417
-
418
- export type ResolveAllParams<
419
- TParentRoute extends AnyRoute,
420
- TParams extends AnyPathParams,
421
- > =
422
- Record<never, string> extends TParentRoute['types']['allParams']
423
- ? TParams
424
- : Expand<
425
- UnionToIntersection<TParentRoute['types']['allParams'] & TParams> & {}
426
- >
427
-
428
- export type RouteConstraints = {
429
- TParentRoute: AnyRoute
430
- TPath: string
431
- TFullPath: string
432
- TCustomId: string
433
- TId: string
434
- TSearchSchema: AnySearchSchema
435
- TFullSearchSchema: AnySearchSchema
436
- TParams: Record<string, any>
437
- TAllParams: Record<string, any>
438
- TParentContext: AnyContext
439
- TRouteContext: RouteContext
440
- TAllContext: AnyContext
441
- TRouterContext: AnyContext
442
- TChildren: unknown
443
- TRouteTree: AnyRoute
444
- }
445
-
446
- export function getRouteApi<
447
- TId extends RouteIds<RegisteredRouter['routeTree']>,
448
- TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
449
- TFullSearchSchema extends Record<
450
- string,
451
- any
452
- > = TRoute['types']['fullSearchSchema'],
453
- TAllParams extends AnyPathParams = TRoute['types']['allParams'],
454
- TAllContext extends Record<string, any> = TRoute['types']['allContext'],
455
- TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],
456
- TLoaderData extends any = TRoute['types']['loaderData'],
457
- >(id: TId) {
458
- return new RouteApi<
459
- TId,
460
- TRoute,
461
- TFullSearchSchema,
462
- TAllParams,
463
- TAllContext,
464
- TLoaderDeps,
465
- TLoaderData
466
- >({ id })
467
- }
468
-
469
- export class RouteApi<
470
- TId extends RouteIds<RegisteredRouter['routeTree']>,
471
- TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
472
- TFullSearchSchema extends Record<
473
- string,
474
- any
475
- > = TRoute['types']['fullSearchSchema'],
476
- TAllParams extends AnyPathParams = TRoute['types']['allParams'],
477
- TAllContext extends Record<string, any> = TRoute['types']['allContext'],
478
- TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],
479
- TLoaderData extends any = TRoute['types']['loaderData'],
480
- > {
481
- id: TId
482
-
483
- /**
484
- * @deprecated Use the `getRouteApi` function instead.
485
- */
486
- constructor({ id }: { id: TId }) {
487
- this.id = id as any
488
- }
489
-
490
- useMatch = <
491
- TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
492
- TRouteMatchState = RouteMatch<TRouteTree, TId>,
493
- TSelected = TRouteMatchState,
494
- >(opts?: {
495
- select?: (match: TRouteMatchState) => TSelected
496
- }): TSelected => {
497
- return useMatch({ select: opts?.select, from: this.id })
498
- }
499
-
500
- useRouteContext = <TSelected = TAllContext>(opts?: {
501
- select?: (s: TAllContext) => TSelected
502
- }): TSelected => {
503
- return useMatch({
504
- from: this.id,
505
- select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),
506
- })
507
- }
508
-
509
- useSearch = <TSelected = TFullSearchSchema>(opts?: {
510
- select?: (s: TFullSearchSchema) => TSelected
511
- }): TSelected => {
512
- return useSearch({ ...opts, from: this.id })
513
- }
514
-
515
- useParams = <TSelected = TAllParams>(opts?: {
516
- select?: (s: TAllParams) => TSelected
517
- }): TSelected => {
518
- return useParams({ ...opts, from: this.id })
519
- }
520
-
521
- useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {
522
- select?: (s: TLoaderDeps) => TSelected
523
- }): TSelected => {
524
- return useLoaderDeps({ ...opts, from: this.id, strict: false } as any)
525
- }
526
-
527
- useLoaderData = <TSelected = TLoaderData>(opts?: {
528
- select?: (s: TLoaderData) => TSelected
529
- }): TSelected => {
530
- return useLoaderData({ ...opts, from: this.id, strict: false } as any)
531
- }
532
-
533
- notFound = (opts?: NotFoundError) => {
534
- return notFound({ routeId: this.id as string, ...opts })
535
- }
536
- }
537
-
538
- export class Route<
539
- TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
540
- in out TPath extends RouteConstraints['TPath'] = '/',
541
- TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
542
- TParentRoute,
543
- TPath
544
- >,
545
- TCustomId extends RouteConstraints['TCustomId'] = string,
546
- TId extends RouteConstraints['TId'] = ResolveId<
547
- TParentRoute,
548
- TCustomId,
549
- TPath
550
- >,
551
- TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
552
- TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
553
- TSearchSchemaUsed extends Record<
554
- string,
555
- any
556
- > = TSearchSchemaInput extends SearchSchemaInput
557
- ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
558
- : TSearchSchema,
559
- TFullSearchSchemaInput extends Record<
560
- string,
561
- any
562
- > = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>,
563
- TFullSearchSchema extends
564
- RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
565
- TParentRoute,
566
- TSearchSchema
567
- >,
568
- TParams extends RouteConstraints['TParams'] = Expand<
569
- Record<ParsePathParams<TPath>, string>
570
- >,
571
- TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<
572
- TParentRoute,
573
- TParams
574
- >,
575
- TRouteContextReturn extends RouteConstraints['TRouteContext'] = RouteContext,
576
- in out TRouteContext extends RouteConstraints['TRouteContext'] = [
577
- TRouteContextReturn,
578
- ] extends [never]
579
- ? RouteContext
580
- : TRouteContextReturn,
581
- in out TAllContext extends Expand<
582
- Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
583
- > = Expand<
584
- Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
585
- >,
586
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
587
- TLoaderDeps extends Record<string, any> = {},
588
- TLoaderDataReturn extends any = unknown,
589
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
590
- ? undefined
591
- : TLoaderDataReturn,
592
- TChildren extends RouteConstraints['TChildren'] = unknown,
593
- TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
594
- > {
595
- isRoot: TParentRoute extends Route<any> ? true : false
596
- options: RouteOptions<
597
- TParentRoute,
598
- TCustomId,
599
- TPath,
600
- TSearchSchemaInput,
601
- TSearchSchema,
602
- TSearchSchemaUsed,
603
- TFullSearchSchemaInput,
604
- TFullSearchSchema,
605
- TParams,
606
- TAllParams,
607
- TRouteContextReturn,
608
- TRouteContext,
609
- TRouterContext,
610
- TAllContext,
611
- TLoaderDeps,
612
- TLoaderDataReturn,
613
- TLoaderData
614
- >
615
-
616
- // Set up in this.init()
617
- parentRoute!: TParentRoute
618
- id!: TId
619
- // customId!: TCustomId
620
- path!: TPath
621
- fullPath!: TFullPath
622
- to!: TrimPathRight<TFullPath>
623
-
624
- // Optional
625
- children?: TChildren
626
- originalIndex?: number
627
- router?: AnyRouter
628
- rank!: number
629
- lazyFn?: () => Promise<LazyRoute<any>>
630
-
631
- /**
632
- * @deprecated Use the `createRoute` function instead.
633
- */
634
- constructor(
635
- options: RouteOptions<
636
- TParentRoute,
637
- TCustomId,
638
- TPath,
639
- TSearchSchemaInput,
640
- TSearchSchema,
641
- TSearchSchemaUsed,
642
- TFullSearchSchemaInput,
643
- TFullSearchSchema,
644
- TParams,
645
- TAllParams,
646
- TRouteContextReturn,
647
- TRouteContext,
648
- TRouterContext,
649
- TAllContext,
650
- TLoaderDeps,
651
- TLoaderDataReturn,
652
- TLoaderData
653
- >,
654
- ) {
655
- this.options = (options as any) || {}
656
- this.isRoot = !options?.getParentRoute as any
657
- invariant(
658
- !((options as any)?.id && (options as any)?.path),
659
- `Route cannot have both an 'id' and a 'path' option.`,
660
- )
661
- ;(this as any).$$typeof = Symbol.for('react.memo')
662
- }
663
-
664
- types!: {
665
- parentRoute: TParentRoute
666
- path: TPath
667
- to: TrimPathRight<TFullPath>
668
- fullPath: TFullPath
669
- customId: TCustomId
670
- id: TId
671
- searchSchema: TSearchSchema
672
- searchSchemaInput: TSearchSchemaInput
673
- searchSchemaUsed: TSearchSchemaUsed
674
- fullSearchSchema: TFullSearchSchema
675
- fullSearchSchemaInput: TFullSearchSchemaInput
676
- params: TParams
677
- allParams: TAllParams
678
- routeContext: TRouteContext
679
- allContext: TAllContext
680
- children: TChildren
681
- routeTree: TRouteTree
682
- routerContext: TRouterContext
683
- loaderData: TLoaderData
684
- loaderDeps: TLoaderDeps
685
- }
686
-
687
- init = (opts: { originalIndex: number }) => {
688
- this.originalIndex = opts.originalIndex
689
-
690
- const options = this.options as RouteOptions<
691
- TParentRoute,
692
- TCustomId,
693
- TPath,
694
- TSearchSchemaInput,
695
- TSearchSchema,
696
- TSearchSchemaUsed,
697
- TFullSearchSchemaInput,
698
- TFullSearchSchema,
699
- TParams,
700
- TAllParams,
701
- TRouteContextReturn,
702
- TRouteContext,
703
- TRouterContext,
704
- TAllContext,
705
- TLoaderDeps,
706
- TLoaderDataReturn,
707
- TLoaderData
708
- > &
709
- RoutePathOptionsIntersection<TCustomId, TPath>
710
-
711
- const isRoot = !options?.path && !options?.id
712
-
713
- this.parentRoute = this.options?.getParentRoute?.()
714
-
715
- if (isRoot) {
716
- this.path = rootRouteId as TPath
717
- } else {
718
- invariant(
719
- this.parentRoute,
720
- `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`,
721
- )
722
- }
723
-
724
- let path: undefined | string = isRoot ? rootRouteId : options.path
725
-
726
- // If the path is anything other than an index path, trim it up
727
- if (path && path !== '/') {
728
- path = trimPathLeft(path)
729
- }
730
-
731
- const customId = options?.id || path
732
-
733
- // Strip the parentId prefix from the first level of children
734
- let id = isRoot
735
- ? rootRouteId
736
- : joinPaths([
737
- (this.parentRoute.id as any) === rootRouteId
738
- ? ''
739
- : this.parentRoute.id,
740
- customId,
741
- ])
742
-
743
- if (path === rootRouteId) {
744
- path = '/'
745
- }
746
-
747
- if (id !== rootRouteId) {
748
- id = joinPaths(['/', id])
749
- }
750
-
751
- const fullPath =
752
- id === rootRouteId ? '/' : joinPaths([this.parentRoute.fullPath, path])
753
-
754
- this.path = path as TPath
755
- this.id = id as TId
756
- // this.customId = customId as TCustomId
757
- this.fullPath = fullPath as TFullPath
758
- this.to = fullPath as TrimPathRight<TFullPath>
759
- }
760
-
761
- addChildren = <TNewChildren extends AnyRoute[]>(
762
- children: TNewChildren,
763
- ): Route<
764
- TParentRoute,
765
- TPath,
766
- TFullPath,
767
- TCustomId,
768
- TId,
769
- TSearchSchemaInput,
770
- TSearchSchema,
771
- TSearchSchemaUsed,
772
- TFullSearchSchemaInput,
773
- TFullSearchSchema,
774
- TParams,
775
- TAllParams,
776
- TRouteContextReturn,
777
- TRouteContext,
778
- TAllContext,
779
- TRouterContext,
780
- TLoaderDeps,
781
- TLoaderDataReturn,
782
- TLoaderData,
783
- TNewChildren,
784
- TRouteTree
785
- > => {
786
- this.children = children as any
787
- return this as any
788
- }
789
-
790
- updateLoader = <TNewLoaderData extends any = unknown>(options: {
791
- loader: RouteLoaderFn<
792
- TAllParams,
793
- TLoaderDeps,
794
- TAllContext,
795
- TRouteContext,
796
- TNewLoaderData
797
- >
798
- }) => {
799
- Object.assign(this.options, options)
800
- return this as unknown as Route<
801
- TParentRoute,
802
- TPath,
803
- TFullPath,
804
- TCustomId,
805
- TId,
806
- TSearchSchemaInput,
807
- TSearchSchema,
808
- TSearchSchemaUsed,
809
- TFullSearchSchemaInput,
810
- TFullSearchSchema,
811
- TParams,
812
- TAllParams,
813
- TRouteContextReturn,
814
- TRouteContext,
815
- TAllContext,
816
- TRouterContext,
817
- TLoaderDeps,
818
- TNewLoaderData,
819
- TChildren,
820
- TRouteTree
821
- >
822
- }
823
-
824
- update = (
825
- options: UpdatableRouteOptions<TAllParams, TFullSearchSchema, TLoaderData>,
826
- ) => {
827
- Object.assign(this.options, options)
828
- return this
829
- }
830
-
831
- lazy = (lazyFn: () => Promise<LazyRoute<any>>) => {
832
- this.lazyFn = lazyFn
833
- return this
834
- }
835
-
836
- useMatch = <
837
- TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
838
- TRouteMatchState = RouteMatch<TRouteTree, TId>,
839
- TSelected = TRouteMatchState,
840
- >(opts?: {
841
- select?: (match: TRouteMatchState) => TSelected
842
- }): TSelected => {
843
- return useMatch({ ...opts, from: this.id })
844
- }
845
-
846
- useRouteContext = <TSelected = TAllContext>(opts?: {
847
- select?: (search: TAllContext) => TSelected
848
- }): TSelected => {
849
- return useMatch({
850
- ...opts,
851
- from: this.id,
852
- select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),
853
- })
854
- }
855
-
856
- useSearch = <TSelected = TFullSearchSchema>(opts?: {
857
- select?: (search: TFullSearchSchema) => TSelected
858
- }): TSelected => {
859
- return useSearch({ ...opts, from: this.id })
860
- }
861
-
862
- useParams = <TSelected = TAllParams>(opts?: {
863
- select?: (search: TAllParams) => TSelected
864
- }): TSelected => {
865
- return useParams({ ...opts, from: this.id })
866
- }
867
-
868
- useLoaderDeps = <TSelected = TLoaderDeps>(opts?: {
869
- select?: (s: TLoaderDeps) => TSelected
870
- }): TSelected => {
871
- return useLoaderDeps({ ...opts, from: this.id } as any)
872
- }
873
-
874
- useLoaderData = <TSelected = TLoaderData>(opts?: {
875
- select?: (search: TLoaderData) => TSelected
876
- }): TSelected => {
877
- return useLoaderData({ ...opts, from: this.id } as any)
878
- }
879
- }
880
-
881
- export function createRoute<
882
- TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
883
- TPath extends RouteConstraints['TPath'] = '/',
884
- TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
885
- TParentRoute,
886
- TPath
887
- >,
888
- TCustomId extends RouteConstraints['TCustomId'] = string,
889
- TId extends RouteConstraints['TId'] = ResolveId<
890
- TParentRoute,
891
- TCustomId,
892
- TPath
893
- >,
894
- TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
895
- TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
896
- TSearchSchemaUsed extends Record<
897
- string,
898
- any
899
- > = TSearchSchemaInput extends SearchSchemaInput
900
- ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
901
- : TSearchSchema,
902
- TFullSearchSchemaInput extends Record<
903
- string,
904
- any
905
- > = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>,
906
- TFullSearchSchema extends
907
- RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
908
- TParentRoute,
909
- TSearchSchema
910
- >,
911
- TParams extends RouteConstraints['TParams'] = Expand<
912
- Record<ParsePathParams<TPath>, string>
913
- >,
914
- TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<
915
- TParentRoute,
916
- TParams
917
- >,
918
- TRouteContextReturn extends RouteConstraints['TRouteContext'] = RouteContext,
919
- TRouteContext extends RouteConstraints['TRouteContext'] = [
920
- TRouteContextReturn,
921
- ] extends [never]
922
- ? RouteContext
923
- : TRouteContextReturn,
924
- TAllContext extends Expand<
925
- Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
926
- > = Expand<
927
- Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
928
- >,
929
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
930
- TLoaderDeps extends Record<string, any> = {},
931
- TLoaderDataReturn extends any = unknown,
932
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
933
- ? undefined
934
- : TLoaderDataReturn,
935
- TChildren extends RouteConstraints['TChildren'] = unknown,
936
- TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
937
- >(
938
- options: RouteOptions<
939
- TParentRoute,
940
- TCustomId,
941
- TPath,
942
- TSearchSchemaInput,
943
- TSearchSchema,
944
- TSearchSchemaUsed,
945
- TFullSearchSchemaInput,
946
- TFullSearchSchema,
947
- TParams,
948
- TAllParams,
949
- TRouteContextReturn,
950
- TRouteContext,
951
- TRouterContext,
952
- TAllContext,
953
- TLoaderDeps,
954
- TLoaderDataReturn,
955
- TLoaderData
956
- >,
957
- ) {
958
- return new Route<
959
- TParentRoute,
960
- TPath,
961
- TFullPath,
962
- TCustomId,
963
- TId,
964
- TSearchSchemaInput,
965
- TSearchSchema,
966
- TSearchSchemaUsed,
967
- TFullSearchSchemaInput,
968
- TFullSearchSchema,
969
- TParams,
970
- TAllParams,
971
- TRouteContextReturn,
972
- TRouteContext,
973
- TAllContext,
974
- TRouterContext,
975
- TLoaderDeps,
976
- TLoaderDataReturn,
977
- TLoaderData,
978
- TChildren,
979
- TRouteTree
980
- >(options)
981
- }
982
-
983
- export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>
984
-
985
- export function createRootRouteWithContext<TRouterContext extends {}>() {
986
- return <
987
- TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
988
- TSearchSchema extends Record<string, any> = RootSearchSchema,
989
- TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
990
- TRouteContextReturn extends RouteContext = RouteContext,
991
- TRouteContext extends RouteContext = [TRouteContextReturn] extends [never]
992
- ? RouteContext
993
- : TRouteContextReturn,
994
- TLoaderDeps extends Record<string, any> = {},
995
- TLoaderDataReturn extends any = unknown,
996
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
997
- ? undefined
998
- : TLoaderDataReturn,
999
- >(
1000
- options?: Omit<
1001
- RouteOptions<
1002
- AnyRoute, // TParentRoute
1003
- RootRouteId, // TCustomId
1004
- '', // TPath
1005
- TSearchSchemaInput, // TSearchSchemaInput
1006
- TSearchSchema, // TSearchSchema
1007
- TSearchSchemaUsed,
1008
- TSearchSchemaUsed, //TFullSearchSchemaInput
1009
- TSearchSchema, // TFullSearchSchema
1010
- {}, // TParams
1011
- {}, // TAllParams
1012
- TRouteContextReturn, // TRouteContextReturn
1013
- TRouteContext, // TRouteContext
1014
- TRouterContext,
1015
- Assign<TRouterContext, TRouteContext>, // TAllContext
1016
- TLoaderDeps,
1017
- TLoaderDataReturn, // TLoaderDataReturn,
1018
- TLoaderData // TLoaderData,
1019
- >,
1020
- | 'path'
1021
- | 'id'
1022
- | 'getParentRoute'
1023
- | 'caseSensitive'
1024
- | 'parseParams'
1025
- | 'stringifyParams'
1026
- >,
1027
- ) => {
1028
- return createRootRoute<
1029
- TSearchSchemaInput,
1030
- TSearchSchema,
1031
- TSearchSchemaUsed,
1032
- TRouteContextReturn,
1033
- TRouteContext,
1034
- TRouterContext,
1035
- TLoaderDeps,
1036
- TLoaderData
1037
- >(options as any)
1038
- }
1039
- }
1040
-
1041
- /**
1042
- * @deprecated Use the `createRootRouteWithContext` function instead.
1043
- */
1044
- export const rootRouteWithContext = createRootRouteWithContext
1045
-
1046
- export type RootSearchSchema = {
1047
- __TRootSearchSchema__: '__TRootSearchSchema__'
1048
- }
1049
-
1050
- export class RootRoute<
1051
- TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
1052
- TSearchSchema extends Record<string, any> = RootSearchSchema,
1053
- TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
1054
- TRouteContextReturn extends RouteContext = RouteContext,
1055
- TRouteContext extends RouteContext = [TRouteContextReturn] extends [never]
1056
- ? RouteContext
1057
- : TRouteContextReturn,
1058
- TRouterContext extends {} = {},
1059
- TLoaderDeps extends Record<string, any> = {},
1060
- TLoaderDataReturn extends any = unknown,
1061
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
1062
- ? undefined
1063
- : TLoaderDataReturn,
1064
- > extends Route<
1065
- any, // TParentRoute
1066
- '/', // TPath
1067
- '/', // TFullPath
1068
- string, // TCustomId
1069
- RootRouteId, // TId
1070
- TSearchSchemaInput, // TSearchSchemaInput
1071
- TSearchSchema, // TSearchSchema
1072
- TSearchSchemaUsed,
1073
- TSearchSchemaUsed, // TFullSearchSchemaInput
1074
- TSearchSchema, // TFullSearchSchema
1075
- {}, // TParams
1076
- {}, // TAllParams
1077
- TRouteContextReturn, // TRouteContextReturn
1078
- TRouteContext, // TRouteContext
1079
- Expand<Assign<TRouterContext, TRouteContext>>, // TAllContext
1080
- TRouterContext, // TRouterContext
1081
- TLoaderDeps,
1082
- TLoaderDataReturn,
1083
- TLoaderData,
1084
- any, // TChildren
1085
- any // TRouteTree
1086
- > {
1087
- /**
1088
- * @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
1089
- */
1090
- constructor(
1091
- options?: Omit<
1092
- RouteOptions<
1093
- AnyRoute, // TParentRoute
1094
- RootRouteId, // TCustomId
1095
- '', // TPath
1096
- TSearchSchemaInput, // TSearchSchemaInput
1097
- TSearchSchema, // TSearchSchema
1098
- TSearchSchemaUsed,
1099
- TSearchSchemaUsed, // TFullSearchSchemaInput
1100
- TSearchSchema, // TFullSearchSchema
1101
- {}, // TParams
1102
- {}, // TAllParams
1103
- TRouteContextReturn, // TRouteContextReturn
1104
- TRouteContext, // TRouteContext
1105
- TRouterContext,
1106
- Assign<TRouterContext, TRouteContext>, // TAllContext
1107
- TLoaderDeps,
1108
- TLoaderDataReturn,
1109
- TLoaderData
1110
- >,
1111
- | 'path'
1112
- | 'id'
1113
- | 'getParentRoute'
1114
- | 'caseSensitive'
1115
- | 'parseParams'
1116
- | 'stringifyParams'
1117
- >,
1118
- ) {
1119
- super(options as any)
1120
- }
1121
- }
1122
-
1123
- export function createRootRoute<
1124
- TSearchSchemaInput extends Record<string, any> = RootSearchSchema,
1125
- TSearchSchema extends Record<string, any> = RootSearchSchema,
1126
- TSearchSchemaUsed extends Record<string, any> = RootSearchSchema,
1127
- TRouteContextReturn extends RouteContext = RouteContext,
1128
- TRouteContext extends RouteContext = [TRouteContextReturn] extends [never]
1129
- ? RouteContext
1130
- : TRouteContextReturn,
1131
- TRouterContext extends {} = {},
1132
- TLoaderDeps extends Record<string, any> = {},
1133
- TLoaderDataReturn extends any = unknown,
1134
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
1135
- ? undefined
1136
- : TLoaderDataReturn,
1137
- >(
1138
- options?: Omit<
1139
- RouteOptions<
1140
- AnyRoute, // TParentRoute
1141
- RootRouteId, // TCustomId
1142
- '', // TPath
1143
- TSearchSchemaInput, // TSearchSchemaInput
1144
- TSearchSchema, // TSearchSchema
1145
- TSearchSchemaUsed,
1146
- TSearchSchemaUsed, // TFullSearchSchemaInput
1147
- TSearchSchema, // TFullSearchSchema
1148
- {}, // TParams
1149
- {}, // TAllParams
1150
- TRouteContextReturn, // TRouteContextReturn
1151
- TRouteContext, // TRouteContext
1152
- TRouterContext,
1153
- Assign<TRouterContext, TRouteContext>, // TAllContext
1154
- TLoaderDeps,
1155
- TLoaderDataReturn,
1156
- TLoaderData
1157
- >,
1158
- | 'path'
1159
- | 'id'
1160
- | 'getParentRoute'
1161
- | 'caseSensitive'
1162
- | 'parseParams'
1163
- | 'stringifyParams'
1164
- >,
1165
- ) {
1166
- return new RootRoute<
1167
- TSearchSchemaInput,
1168
- TSearchSchema,
1169
- TSearchSchemaUsed,
1170
- TRouteContextReturn,
1171
- TRouteContext,
1172
- TRouterContext,
1173
- TLoaderDeps,
1174
- TLoaderDataReturn,
1175
- TLoaderData
1176
- >(options)
1177
- }
1178
-
1179
- export type ResolveFullPath<
1180
- TParentRoute extends AnyRoute,
1181
- TPath extends string,
1182
- TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,
1183
- > = TPrefixed extends RootRouteId ? '/' : TPrefixed
1184
-
1185
- type RoutePrefix<
1186
- TPrefix extends string,
1187
- TPath extends string,
1188
- > = string extends TPath
1189
- ? RootRouteId
1190
- : TPath extends string
1191
- ? TPrefix extends RootRouteId
1192
- ? TPath extends '/'
1193
- ? '/'
1194
- : `/${TrimPath<TPath>}`
1195
- : `${TPrefix}/${TPath}` extends '/'
1196
- ? '/'
1197
- : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`
1198
- : never
1199
-
1200
- export type TrimPath<T extends string> = '' extends T
1201
- ? ''
1202
- : TrimPathRight<TrimPathLeft<T>>
1203
-
1204
- export type TrimPathLeft<T extends string> =
1205
- T extends `${RootRouteId}/${infer U}`
1206
- ? TrimPathLeft<U>
1207
- : T extends `/${infer U}`
1208
- ? TrimPathLeft<U>
1209
- : T
1210
- export type TrimPathRight<T extends string> = T extends '/'
1211
- ? '/'
1212
- : T extends `${infer U}/`
1213
- ? TrimPathRight<U>
1214
- : T
1215
-
1216
- export type RouteMask<TRouteTree extends AnyRoute> = {
1217
- routeTree: TRouteTree
1218
- from: RoutePaths<TRouteTree>
1219
- to?: any
1220
- params?: any
1221
- search?: any
1222
- hash?: any
1223
- state?: any
1224
- unmaskOnReload?: boolean
1225
- }
1226
-
1227
- export function createRouteMask<
1228
- TRouteTree extends AnyRoute,
1229
- TFrom extends RoutePaths<TRouteTree>,
1230
- TTo extends string,
1231
- >(
1232
- opts: {
1233
- routeTree: TRouteTree
1234
- } & ToSubOptions<TRouteTree, TFrom, TTo>,
1235
- ): RouteMask<TRouteTree> {
1236
- return opts as any
1237
- }
1238
-
1239
- /**
1240
- * @deprecated Use `ErrorComponentProps` instead.
1241
- */
1242
- export type ErrorRouteProps = {
1243
- error: unknown
1244
- info: { componentStack: string }
1245
- }
1246
-
1247
- export type ErrorComponentProps = {
1248
- error: unknown
1249
- info: { componentStack: string }
1250
- }
1251
- export type NotFoundRouteProps = {
1252
- // TODO: Make sure this is `| null | undefined` (this is for global not-founds)
1253
- data: unknown
1254
- }
1255
- //
1256
-
1257
- export type ReactNode = any
1258
-
1259
- export type SyncRouteComponent<TProps> =
1260
- | ((props: TProps) => ReactNode)
1261
- | React.LazyExoticComponent<(props: TProps) => ReactNode>
1262
-
1263
- export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
1264
- preload?: () => Promise<void>
1265
- }
1266
-
1267
- export type RouteComponent<TProps = any> = SyncRouteComponent<TProps> &
1268
- AsyncRouteComponent<TProps>
1269
-
1270
- export type ErrorRouteComponent = RouteComponent<ErrorComponentProps>
1271
-
1272
- export type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>
1273
-
1274
- export class NotFoundRoute<
1275
- TParentRoute extends AnyRootRoute,
1276
- TSearchSchemaInput extends Record<string, any> = {},
1277
- TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
1278
- TSearchSchemaUsed extends RouteConstraints['TSearchSchema'] = {},
1279
- TFullSearchSchemaInput extends
1280
- RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchemaInput<
1281
- TParentRoute,
1282
- TSearchSchemaUsed
1283
- >,
1284
- TFullSearchSchema extends
1285
- RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
1286
- TParentRoute,
1287
- TSearchSchema
1288
- >,
1289
- TRouteContextReturn extends RouteConstraints['TRouteContext'] = AnyContext,
1290
- TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
1291
- TAllContext extends Expand<
1292
- Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
1293
- > = Expand<
1294
- Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
1295
- >,
1296
- TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
1297
- TLoaderDeps extends Record<string, any> = {},
1298
- TLoaderDataReturn extends any = unknown,
1299
- TLoaderData extends any = [TLoaderDataReturn] extends [never]
1300
- ? undefined
1301
- : TLoaderDataReturn,
1302
- TChildren extends RouteConstraints['TChildren'] = unknown,
1303
- TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute,
1304
- > extends Route<
1305
- TParentRoute,
1306
- '/404',
1307
- '/404',
1308
- '404',
1309
- '404',
1310
- TSearchSchemaInput,
1311
- TSearchSchema,
1312
- TSearchSchemaUsed,
1313
- TFullSearchSchemaInput,
1314
- TFullSearchSchema,
1315
- {},
1316
- {},
1317
- TRouteContextReturn,
1318
- TRouteContext,
1319
- TAllContext,
1320
- TRouterContext,
1321
- TLoaderDeps,
1322
- TLoaderDataReturn,
1323
- TLoaderData,
1324
- TChildren,
1325
- TRouteTree
1326
- > {
1327
- constructor(
1328
- options: Omit<
1329
- RouteOptions<
1330
- TParentRoute,
1331
- string,
1332
- string,
1333
- TSearchSchemaInput,
1334
- TSearchSchema,
1335
- TSearchSchemaUsed,
1336
- TFullSearchSchemaInput,
1337
- TFullSearchSchema,
1338
- {},
1339
- {},
1340
- TRouteContextReturn,
1341
- TRouteContext,
1342
- TRouterContext,
1343
- TAllContext,
1344
- TLoaderDeps,
1345
- TLoaderDataReturn,
1346
- TLoaderData
1347
- >,
1348
- 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id'
1349
- >,
1350
- ) {
1351
- super({
1352
- ...(options as any),
1353
- id: '404',
1354
- })
1355
- }
1356
- }