@tanstack/solid-router 1.108.0

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