react-router 7.18.0 → 8.0.0-pre.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 (285) hide show
  1. package/dist/development/dom-export.d.ts +6 -172
  2. package/dist/development/dom-export.js +12 -1009
  3. package/dist/development/index-react-server-client.d.ts +7 -4
  4. package/dist/development/index-react-server-client.js +8 -52
  5. package/dist/development/index-react-server.d.ts +1650 -1641
  6. package/dist/development/index-react-server.js +2882 -3664
  7. package/dist/development/index.d.ts +42 -1476
  8. package/dist/development/index.js +36 -2553
  9. package/dist/development/lib/actions.js +50 -0
  10. package/dist/development/lib/components.d.ts +1030 -0
  11. package/dist/development/lib/components.js +841 -0
  12. package/dist/development/lib/context.d.ts +83 -0
  13. package/dist/development/lib/context.js +41 -0
  14. package/dist/development/lib/dom/dom.d.ts +119 -0
  15. package/dist/development/lib/dom/dom.js +143 -0
  16. package/dist/development/lib/dom/lib.d.ts +2053 -0
  17. package/dist/development/lib/dom/lib.js +1271 -0
  18. package/dist/development/lib/dom/server.d.ts +138 -0
  19. package/dist/development/lib/dom/server.js +301 -0
  20. package/dist/development/lib/dom/ssr/components.d.ts +198 -0
  21. package/dist/development/lib/dom/ssr/components.js +589 -0
  22. package/dist/development/lib/dom/ssr/data.js +29 -0
  23. package/dist/development/lib/dom/ssr/entry.d.ts +60 -0
  24. package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  25. package/dist/development/lib/dom/ssr/errorBoundaries.js +87 -0
  26. package/dist/development/lib/dom/ssr/fallback.js +33 -0
  27. package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
  28. package/dist/development/lib/dom/ssr/fog-of-war.js +180 -0
  29. package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
  30. package/dist/development/lib/dom/ssr/hydration.js +29 -0
  31. package/dist/development/lib/dom/ssr/invariant.js +16 -0
  32. package/dist/development/lib/dom/ssr/links.js +170 -0
  33. package/dist/development/lib/dom/ssr/markup.js +24 -0
  34. package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
  35. package/dist/development/lib/dom/ssr/routeModules.js +31 -0
  36. package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +62 -0
  37. package/dist/development/lib/dom/ssr/routes-test-stub.js +108 -0
  38. package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
  39. package/dist/development/lib/dom/ssr/routes.js +303 -0
  40. package/dist/development/lib/dom/ssr/server.d.ts +48 -0
  41. package/dist/development/lib/dom/ssr/server.js +69 -0
  42. package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
  43. package/dist/development/lib/dom/ssr/single-fetch.js +345 -0
  44. package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
  45. package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
  46. package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
  47. package/dist/development/lib/dom-export/hydrated-router.js +150 -0
  48. package/dist/development/lib/errors.js +29 -0
  49. package/dist/development/lib/hooks.d.ts +947 -0
  50. package/dist/development/lib/hooks.js +1388 -0
  51. package/dist/development/lib/href.d.ts +20 -0
  52. package/dist/development/lib/href.js +50 -0
  53. package/dist/development/lib/router/history.d.ts +258 -0
  54. package/dist/development/lib/router/history.js +372 -0
  55. package/dist/development/lib/router/instrumentation.d.ts +86 -0
  56. package/dist/development/lib/router/instrumentation.js +213 -0
  57. package/dist/development/lib/router/links.d.ts +114 -0
  58. package/dist/development/lib/router/router.d.ts +663 -0
  59. package/dist/development/lib/router/router.js +2988 -0
  60. package/dist/development/lib/router/url.js +18 -0
  61. package/dist/development/lib/router/utils.d.ts +948 -0
  62. package/dist/development/lib/router/utils.js +810 -0
  63. package/dist/development/lib/rsc/browser.d.ts +137 -0
  64. package/dist/development/lib/rsc/browser.js +603 -0
  65. package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
  66. package/dist/development/lib/rsc/errorBoundaries.js +90 -0
  67. package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
  68. package/dist/development/lib/rsc/html-stream/browser.js +74 -0
  69. package/dist/development/lib/rsc/html-stream/server.js +78 -0
  70. package/dist/development/lib/rsc/route-modules.js +27 -0
  71. package/dist/development/lib/rsc/server.rsc.d.ts +219 -0
  72. package/dist/development/lib/rsc/server.ssr.d.ts +129 -0
  73. package/dist/development/lib/rsc/server.ssr.js +404 -0
  74. package/dist/development/lib/server-runtime/build.d.ts +66 -0
  75. package/dist/development/lib/server-runtime/cookies.d.ts +66 -0
  76. package/dist/development/lib/server-runtime/cookies.js +139 -0
  77. package/dist/development/lib/server-runtime/crypto.js +43 -0
  78. package/dist/development/lib/server-runtime/data.d.ts +13 -0
  79. package/dist/development/lib/server-runtime/data.js +25 -0
  80. package/dist/development/lib/server-runtime/dev.d.ts +9 -0
  81. package/dist/development/lib/server-runtime/dev.js +26 -0
  82. package/dist/development/lib/server-runtime/entry.js +20 -0
  83. package/dist/development/lib/server-runtime/errors.js +75 -0
  84. package/dist/development/lib/server-runtime/headers.js +73 -0
  85. package/dist/development/lib/server-runtime/invariant.js +19 -0
  86. package/dist/development/lib/server-runtime/mode.d.ts +12 -0
  87. package/dist/development/lib/server-runtime/mode.js +25 -0
  88. package/dist/development/lib/server-runtime/routeMatching.js +28 -0
  89. package/dist/development/lib/server-runtime/routes.d.ts +13 -0
  90. package/dist/development/lib/server-runtime/routes.js +74 -0
  91. package/dist/development/lib/server-runtime/server.d.ts +10 -0
  92. package/dist/development/lib/server-runtime/server.js +345 -0
  93. package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
  94. package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
  95. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +45 -0
  96. package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
  97. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +52 -0
  98. package/dist/development/lib/server-runtime/sessions.d.ts +145 -0
  99. package/dist/development/lib/server-runtime/sessions.js +98 -0
  100. package/dist/development/lib/server-runtime/single-fetch.d.ts +7 -0
  101. package/dist/development/lib/server-runtime/single-fetch.js +215 -0
  102. package/dist/development/lib/server-runtime/urls.js +28 -0
  103. package/dist/development/lib/server-runtime/warnings.js +20 -0
  104. package/dist/development/lib/types/future.d.ts +9 -0
  105. package/dist/development/lib/types/internal.d.ts +26 -177
  106. package/dist/development/lib/types/internal.js +3 -2
  107. package/dist/development/{register-roq_0qYo.d.ts → lib/types/register.d.ts} +9 -15
  108. package/dist/development/lib/types/route-data.d.ts +113 -0
  109. package/dist/development/lib/types/route-module-annotations.d.ts +149 -0
  110. package/dist/development/lib/types/route-module.d.ts +19 -0
  111. package/dist/development/lib/types/serializes-to.d.ts +13 -0
  112. package/dist/development/lib/types/utils.d.ts +11 -0
  113. package/dist/development/vendor/turbo-stream-v2/flatten.js +159 -0
  114. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +179 -0
  115. package/dist/development/vendor/turbo-stream-v2/unflatten.js +199 -0
  116. package/dist/development/vendor/turbo-stream-v2/utils.js +39 -0
  117. package/dist/production/dom-export.d.ts +6 -172
  118. package/dist/production/dom-export.js +12 -1009
  119. package/dist/production/index-react-server-client.d.ts +7 -4
  120. package/dist/production/index-react-server-client.js +8 -52
  121. package/dist/production/index-react-server.d.ts +1650 -1641
  122. package/dist/production/index-react-server.js +2873 -3664
  123. package/dist/production/index.d.ts +42 -1476
  124. package/dist/production/index.js +36 -2553
  125. package/dist/production/lib/actions.js +50 -0
  126. package/dist/production/lib/components.d.ts +1030 -0
  127. package/dist/production/lib/components.js +841 -0
  128. package/dist/production/lib/context.d.ts +83 -0
  129. package/dist/production/lib/context.js +41 -0
  130. package/dist/production/lib/dom/dom.d.ts +119 -0
  131. package/dist/production/lib/dom/dom.js +143 -0
  132. package/dist/production/lib/dom/lib.d.ts +2053 -0
  133. package/dist/production/lib/dom/lib.js +1271 -0
  134. package/dist/production/lib/dom/server.d.ts +138 -0
  135. package/dist/production/lib/dom/server.js +301 -0
  136. package/dist/production/lib/dom/ssr/components.d.ts +198 -0
  137. package/dist/production/lib/dom/ssr/components.js +589 -0
  138. package/dist/production/lib/dom/ssr/data.js +29 -0
  139. package/dist/production/lib/dom/ssr/entry.d.ts +60 -0
  140. package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  141. package/dist/production/lib/dom/ssr/errorBoundaries.js +87 -0
  142. package/dist/production/lib/dom/ssr/fallback.js +23 -0
  143. package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
  144. package/dist/production/lib/dom/ssr/fog-of-war.js +180 -0
  145. package/dist/production/lib/dom/ssr/hydration.d.ts +32 -0
  146. package/dist/production/lib/dom/ssr/hydration.js +29 -0
  147. package/dist/production/lib/dom/ssr/invariant.js +16 -0
  148. package/dist/production/lib/dom/ssr/links.js +170 -0
  149. package/dist/production/lib/dom/ssr/markup.js +24 -0
  150. package/dist/production/lib/dom/ssr/routeModules.d.ts +206 -0
  151. package/dist/production/lib/dom/ssr/routeModules.js +31 -0
  152. package/dist/production/lib/dom/ssr/routes-test-stub.d.ts +62 -0
  153. package/dist/production/lib/dom/ssr/routes-test-stub.js +108 -0
  154. package/dist/production/lib/dom/ssr/routes.d.ts +33 -0
  155. package/dist/production/lib/dom/ssr/routes.js +303 -0
  156. package/dist/production/lib/dom/ssr/server.d.ts +48 -0
  157. package/dist/production/lib/dom/ssr/server.js +69 -0
  158. package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
  159. package/dist/production/lib/dom/ssr/single-fetch.js +345 -0
  160. package/dist/production/lib/dom-export/dom-router-provider.d.ts +9 -0
  161. package/dist/production/lib/dom-export/dom-router-provider.js +22 -0
  162. package/dist/production/lib/dom-export/hydrated-router.d.ts +125 -0
  163. package/dist/production/lib/dom-export/hydrated-router.js +150 -0
  164. package/dist/production/lib/errors.js +29 -0
  165. package/dist/production/lib/hooks.d.ts +947 -0
  166. package/dist/production/lib/hooks.js +1373 -0
  167. package/dist/production/lib/href.d.ts +20 -0
  168. package/dist/production/lib/href.js +50 -0
  169. package/dist/production/lib/router/history.d.ts +258 -0
  170. package/dist/production/lib/router/history.js +372 -0
  171. package/dist/production/lib/router/instrumentation.d.ts +86 -0
  172. package/dist/production/lib/router/instrumentation.js +213 -0
  173. package/dist/production/lib/router/links.d.ts +114 -0
  174. package/dist/production/lib/router/router.d.ts +663 -0
  175. package/dist/production/lib/router/router.js +2988 -0
  176. package/dist/production/lib/router/url.js +18 -0
  177. package/dist/production/lib/router/utils.d.ts +948 -0
  178. package/dist/production/lib/router/utils.js +801 -0
  179. package/dist/production/lib/rsc/browser.d.ts +137 -0
  180. package/dist/production/lib/rsc/browser.js +603 -0
  181. package/dist/production/lib/rsc/errorBoundaries.d.ts +11 -0
  182. package/dist/production/lib/rsc/errorBoundaries.js +90 -0
  183. package/dist/production/lib/rsc/html-stream/browser.d.ts +48 -0
  184. package/dist/production/lib/rsc/html-stream/browser.js +74 -0
  185. package/dist/production/lib/rsc/html-stream/server.js +78 -0
  186. package/dist/production/lib/rsc/route-modules.js +27 -0
  187. package/dist/production/lib/rsc/server.rsc.d.ts +219 -0
  188. package/dist/production/lib/rsc/server.ssr.d.ts +129 -0
  189. package/dist/production/lib/rsc/server.ssr.js +404 -0
  190. package/dist/production/lib/server-runtime/build.d.ts +66 -0
  191. package/dist/production/lib/server-runtime/cookies.d.ts +66 -0
  192. package/dist/production/lib/server-runtime/cookies.js +139 -0
  193. package/dist/production/lib/server-runtime/crypto.js +43 -0
  194. package/dist/production/lib/server-runtime/data.d.ts +13 -0
  195. package/dist/production/lib/server-runtime/data.js +25 -0
  196. package/dist/production/lib/server-runtime/dev.d.ts +9 -0
  197. package/dist/production/lib/server-runtime/dev.js +26 -0
  198. package/dist/production/lib/server-runtime/entry.js +20 -0
  199. package/dist/production/lib/server-runtime/errors.js +75 -0
  200. package/dist/production/lib/server-runtime/headers.js +73 -0
  201. package/dist/production/lib/server-runtime/invariant.js +19 -0
  202. package/dist/production/lib/server-runtime/mode.d.ts +12 -0
  203. package/dist/production/lib/server-runtime/mode.js +25 -0
  204. package/dist/production/lib/server-runtime/routeMatching.js +28 -0
  205. package/dist/production/lib/server-runtime/routes.d.ts +13 -0
  206. package/dist/production/lib/server-runtime/routes.js +74 -0
  207. package/dist/production/lib/server-runtime/server.d.ts +10 -0
  208. package/dist/production/lib/server-runtime/server.js +345 -0
  209. package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
  210. package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
  211. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +45 -0
  212. package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
  213. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +52 -0
  214. package/dist/production/lib/server-runtime/sessions.d.ts +145 -0
  215. package/dist/production/lib/server-runtime/sessions.js +98 -0
  216. package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
  217. package/dist/production/lib/server-runtime/single-fetch.js +215 -0
  218. package/dist/production/lib/server-runtime/urls.js +28 -0
  219. package/dist/production/lib/server-runtime/warnings.js +20 -0
  220. package/dist/production/lib/types/future.d.ts +9 -0
  221. package/dist/production/lib/types/internal.d.ts +26 -177
  222. package/dist/production/lib/types/internal.js +3 -2
  223. package/dist/production/{register-roq_0qYo.d.ts → lib/types/register.d.ts} +9 -15
  224. package/dist/production/lib/types/route-data.d.ts +113 -0
  225. package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
  226. package/dist/production/lib/types/route-module.d.ts +19 -0
  227. package/dist/production/lib/types/serializes-to.d.ts +13 -0
  228. package/dist/production/lib/types/utils.d.ts +11 -0
  229. package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
  230. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +179 -0
  231. package/dist/production/vendor/turbo-stream-v2/unflatten.js +199 -0
  232. package/dist/production/vendor/turbo-stream-v2/utils.js +39 -0
  233. package/docs/explanation/code-splitting.md +16 -0
  234. package/docs/how-to/middleware.md +6 -41
  235. package/docs/how-to/react-server-components.md +1 -1
  236. package/docs/upgrading/future.md +0 -249
  237. package/package.json +43 -87
  238. package/dist/development/browser-B2PdsXXH.d.ts +0 -318
  239. package/dist/development/browser-DBmQ1yAR.d.mts +0 -318
  240. package/dist/development/chunk-4ZMWKKQ3.mjs +0 -11606
  241. package/dist/development/chunk-E4MTK73K.mjs +0 -2517
  242. package/dist/development/chunk-U7ORXROY.js +0 -10307
  243. package/dist/development/chunk-WW7PN6QI.js +0 -188
  244. package/dist/development/chunk-YL5M26XI.js +0 -1366
  245. package/dist/development/context-CeD5LmaF.d.mts +0 -1779
  246. package/dist/development/data-CjO11-hU.d.ts +0 -1740
  247. package/dist/development/data-DEjBmEfD.d.mts +0 -1740
  248. package/dist/development/dom-export.d.mts +0 -172
  249. package/dist/development/dom-export.mjs +0 -1010
  250. package/dist/development/index-react-server-client-3ykjivgQ.d.ts +0 -3677
  251. package/dist/development/index-react-server-client-CACgcj2J.d.mts +0 -2614
  252. package/dist/development/index-react-server-client.d.mts +0 -4
  253. package/dist/development/index-react-server-client.mjs +0 -59
  254. package/dist/development/index-react-server.d.mts +0 -2711
  255. package/dist/development/index-react-server.mjs +0 -3803
  256. package/dist/development/index.d.mts +0 -1479
  257. package/dist/development/index.mjs +0 -275
  258. package/dist/development/instrumentation-Dkmpzd13.d.ts +0 -715
  259. package/dist/development/lib/types/internal.d.mts +0 -184
  260. package/dist/development/lib/types/internal.mjs +0 -10
  261. package/dist/development/register-CmkRspdl.d.mts +0 -30
  262. package/dist/production/browser-B2PdsXXH.d.ts +0 -318
  263. package/dist/production/browser-DBmQ1yAR.d.mts +0 -318
  264. package/dist/production/chunk-3Z6WS2WZ.js +0 -188
  265. package/dist/production/chunk-BIP66BKV.js +0 -1366
  266. package/dist/production/chunk-EGOTSXNH.mjs +0 -2517
  267. package/dist/production/chunk-IUPBOWYO.js +0 -10307
  268. package/dist/production/chunk-M7NGGUU6.mjs +0 -11606
  269. package/dist/production/context-CeD5LmaF.d.mts +0 -1779
  270. package/dist/production/data-CjO11-hU.d.ts +0 -1740
  271. package/dist/production/data-DEjBmEfD.d.mts +0 -1740
  272. package/dist/production/dom-export.d.mts +0 -172
  273. package/dist/production/dom-export.mjs +0 -1010
  274. package/dist/production/index-react-server-client-3ykjivgQ.d.ts +0 -3677
  275. package/dist/production/index-react-server-client-CACgcj2J.d.mts +0 -2614
  276. package/dist/production/index-react-server-client.d.mts +0 -4
  277. package/dist/production/index-react-server-client.mjs +0 -59
  278. package/dist/production/index-react-server.d.mts +0 -2711
  279. package/dist/production/index-react-server.mjs +0 -3803
  280. package/dist/production/index.d.mts +0 -1479
  281. package/dist/production/index.mjs +0 -275
  282. package/dist/production/instrumentation-Dkmpzd13.d.ts +0 -715
  283. package/dist/production/lib/types/internal.d.mts +0 -184
  284. package/dist/production/lib/types/internal.mjs +0 -10
  285. package/dist/production/register-CmkRspdl.d.mts +0 -30
@@ -1,1779 +0,0 @@
1
- import { m as HTMLFormMethod, n as FormEncType, o as LoaderFunctionArgs, p as MiddlewareEnabled, c as RouterContextProvider, q as AppLoadContext, r as RouteObject, s as History, t as MaybePromise, u as MapRoutePropertiesFunction, v as Action, L as Location, w as DataRouteMatch, x as Submission, y as RouteData, z as DataStrategyFunction, B as PatchRoutesOnNavigationFunction, E as DataRouteObject, I as RouteBranch, J as RouteManifest, U as UIMatch, T as To, K as Path, P as Params, O as InitialEntry, Q as NonIndexRouteObject, V as LazyRouteFunction, W as IndexRouteObject, X as RouteMatch, Y as TrackedPromise } from './data-DEjBmEfD.mjs';
2
- import * as React from 'react';
3
-
4
- type ServerInstrumentation = {
5
- handler?: InstrumentRequestHandlerFunction;
6
- route?: InstrumentRouteFunction;
7
- };
8
- type ClientInstrumentation = {
9
- router?: InstrumentRouterFunction;
10
- route?: InstrumentRouteFunction;
11
- };
12
- type InstrumentRequestHandlerFunction = (handler: InstrumentableRequestHandler) => void;
13
- type InstrumentRouterFunction = (router: InstrumentableRouter) => void;
14
- type InstrumentRouteFunction = (route: InstrumentableRoute) => void;
15
- type InstrumentationHandlerResult = {
16
- status: "success";
17
- error: undefined;
18
- } | {
19
- status: "error";
20
- error: Error;
21
- };
22
- type InstrumentFunction<T> = (handler: () => Promise<InstrumentationHandlerResult>, info: T) => Promise<void>;
23
- type ReadonlyRequest = {
24
- method: string;
25
- url: string;
26
- headers: Pick<Headers, "get">;
27
- };
28
- type ReadonlyContext = MiddlewareEnabled extends true ? Pick<RouterContextProvider, "get"> : Readonly<AppLoadContext>;
29
- type InstrumentableRoute = {
30
- id: string;
31
- index: boolean | undefined;
32
- path: string | undefined;
33
- instrument(instrumentations: RouteInstrumentations): void;
34
- };
35
- type RouteInstrumentations = {
36
- lazy?: InstrumentFunction<RouteLazyInstrumentationInfo>;
37
- "lazy.loader"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
38
- "lazy.action"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
39
- "lazy.middleware"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
40
- middleware?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
41
- loader?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
42
- action?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
43
- };
44
- type RouteLazyInstrumentationInfo = undefined;
45
- type RouteHandlerInstrumentationInfo = Readonly<{
46
- request: ReadonlyRequest;
47
- params: LoaderFunctionArgs["params"];
48
- pattern: string;
49
- context: ReadonlyContext;
50
- }>;
51
- type InstrumentableRouter = {
52
- instrument(instrumentations: RouterInstrumentations): void;
53
- };
54
- type RouterInstrumentations = {
55
- navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo>;
56
- fetch?: InstrumentFunction<RouterFetchInstrumentationInfo>;
57
- };
58
- type RouterNavigationInstrumentationInfo = Readonly<{
59
- to: string | number;
60
- currentUrl: string;
61
- formMethod?: HTMLFormMethod;
62
- formEncType?: FormEncType;
63
- formData?: FormData;
64
- body?: any;
65
- }>;
66
- type RouterFetchInstrumentationInfo = Readonly<{
67
- href: string;
68
- currentUrl: string;
69
- fetcherKey: string;
70
- formMethod?: HTMLFormMethod;
71
- formEncType?: FormEncType;
72
- formData?: FormData;
73
- body?: any;
74
- }>;
75
- type InstrumentableRequestHandler = {
76
- instrument(instrumentations: RequestHandlerInstrumentations): void;
77
- };
78
- type RequestHandlerInstrumentations = {
79
- request?: InstrumentFunction<RequestHandlerInstrumentationInfo>;
80
- };
81
- type RequestHandlerInstrumentationInfo = Readonly<{
82
- request: ReadonlyRequest;
83
- context: ReadonlyContext | undefined;
84
- }>;
85
-
86
- /**
87
- * A Router instance manages all navigation and data loading/mutations
88
- */
89
- interface Router$1 {
90
- /**
91
- * @private
92
- * PRIVATE - DO NOT USE
93
- *
94
- * Return the basename for the router
95
- */
96
- get basename(): RouterInit["basename"];
97
- /**
98
- * @private
99
- * PRIVATE - DO NOT USE
100
- *
101
- * Return the future config for the router
102
- */
103
- get future(): FutureConfig;
104
- /**
105
- * @private
106
- * PRIVATE - DO NOT USE
107
- *
108
- * Return the current state of the router
109
- */
110
- get state(): RouterState;
111
- /**
112
- * @private
113
- * PRIVATE - DO NOT USE
114
- *
115
- * Return the routes for this router instance
116
- */
117
- get routes(): DataRouteObject[];
118
- /**
119
- * @private
120
- * PRIVATE - DO NOT USE
121
- *
122
- * Return the route branches for this router instance
123
- */
124
- get branches(): RouteBranch<DataRouteObject>[] | undefined;
125
- /**
126
- * @private
127
- * PRIVATE - DO NOT USE
128
- *
129
- * Return the manifest for this router instance
130
- */
131
- get manifest(): RouteManifest;
132
- /**
133
- * @private
134
- * PRIVATE - DO NOT USE
135
- *
136
- * Return the window associated with the router
137
- */
138
- get window(): RouterInit["window"];
139
- /**
140
- * @private
141
- * PRIVATE - DO NOT USE
142
- *
143
- * Initialize the router, including adding history listeners and kicking off
144
- * initial data fetches. Returns a function to cleanup listeners and abort
145
- * any in-progress loads
146
- */
147
- initialize(): Router$1;
148
- /**
149
- * @private
150
- * PRIVATE - DO NOT USE
151
- *
152
- * Subscribe to router.state updates
153
- *
154
- * @param fn function to call with the new state
155
- */
156
- subscribe(fn: RouterSubscriber): () => void;
157
- /**
158
- * @private
159
- * PRIVATE - DO NOT USE
160
- *
161
- * Enable scroll restoration behavior in the router
162
- *
163
- * @param savedScrollPositions Object that will manage positions, in case
164
- * it's being restored from sessionStorage
165
- * @param getScrollPosition Function to get the active Y scroll position
166
- * @param getKey Function to get the key to use for restoration
167
- */
168
- enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
169
- /**
170
- * @private
171
- * PRIVATE - DO NOT USE
172
- *
173
- * Navigate forward/backward in the history stack
174
- * @param to Delta to move in the history stack
175
- */
176
- navigate(to: number): Promise<void>;
177
- /**
178
- * Navigate to the given path
179
- * @param to Path to navigate to
180
- * @param opts Navigation options (method, submission, etc.)
181
- */
182
- navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
183
- /**
184
- * @private
185
- * PRIVATE - DO NOT USE
186
- *
187
- * Trigger a fetcher load/submission
188
- *
189
- * @param key Fetcher key
190
- * @param routeId Route that owns the fetcher
191
- * @param href href to fetch
192
- * @param opts Fetcher options, (method, submission, etc.)
193
- */
194
- fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
195
- /**
196
- * @private
197
- * PRIVATE - DO NOT USE
198
- *
199
- * Trigger a revalidation of all current route loaders and fetcher loads
200
- */
201
- revalidate(): Promise<void>;
202
- /**
203
- * @private
204
- * PRIVATE - DO NOT USE
205
- *
206
- * Utility function to create an href for the given location
207
- * @param location
208
- */
209
- createHref(location: Location | URL): string;
210
- /**
211
- * @private
212
- * PRIVATE - DO NOT USE
213
- *
214
- * Utility function to URL encode a destination path according to the internal
215
- * history implementation
216
- * @param to
217
- */
218
- encodeLocation(to: To): Path;
219
- /**
220
- * @private
221
- * PRIVATE - DO NOT USE
222
- *
223
- * Get/create a fetcher for the given key
224
- * @param key
225
- */
226
- getFetcher<TData = any>(key: string): Fetcher<TData>;
227
- /**
228
- * @internal
229
- * PRIVATE - DO NOT USE
230
- *
231
- * Reset the fetcher for a given key
232
- * @param key
233
- */
234
- resetFetcher(key: string, opts?: {
235
- reason?: unknown;
236
- }): void;
237
- /**
238
- * @private
239
- * PRIVATE - DO NOT USE
240
- *
241
- * Delete the fetcher for a given key
242
- * @param key
243
- */
244
- deleteFetcher(key: string): void;
245
- /**
246
- * @private
247
- * PRIVATE - DO NOT USE
248
- *
249
- * Cleanup listeners and abort any in-progress loads
250
- */
251
- dispose(): void;
252
- /**
253
- * @private
254
- * PRIVATE - DO NOT USE
255
- *
256
- * Get a navigation blocker
257
- * @param key The identifier for the blocker
258
- * @param fn The blocker function implementation
259
- */
260
- getBlocker(key: string, fn: BlockerFunction): Blocker;
261
- /**
262
- * @private
263
- * PRIVATE - DO NOT USE
264
- *
265
- * Delete a navigation blocker
266
- * @param key The identifier for the blocker
267
- */
268
- deleteBlocker(key: string): void;
269
- /**
270
- * @private
271
- * PRIVATE DO NOT USE
272
- *
273
- * Patch additional children routes into an existing parent route
274
- * @param routeId The parent route id or a callback function accepting `patch`
275
- * to perform batch patching
276
- * @param children The additional children routes
277
- * @param unstable_allowElementMutations Allow mutation or route elements on
278
- * existing routes. Intended for RSC-usage
279
- * only.
280
- */
281
- patchRoutes(routeId: string | null, children: RouteObject[], unstable_allowElementMutations?: boolean): void;
282
- /**
283
- * @private
284
- * PRIVATE - DO NOT USE
285
- *
286
- * HMR needs to pass in-flight route updates to React Router
287
- * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
288
- */
289
- _internalSetRoutes(routes: RouteObject[]): void;
290
- /**
291
- * @private
292
- * PRIVATE - DO NOT USE
293
- *
294
- * Cause subscribers to re-render. This is used to force a re-render.
295
- */
296
- _internalSetStateDoNotUseOrYouWillBreakYourApp(state: Partial<RouterState>): void;
297
- /**
298
- * @private
299
- * PRIVATE - DO NOT USE
300
- *
301
- * Internal fetch AbortControllers accessed by unit tests
302
- */
303
- _internalFetchControllers: Map<string, AbortController>;
304
- }
305
- /**
306
- * State maintained internally by the router. During a navigation, all states
307
- * reflect the "old" location unless otherwise noted.
308
- */
309
- interface RouterState {
310
- /**
311
- * The action of the most recent navigation
312
- */
313
- historyAction: Action;
314
- /**
315
- * The current location reflected by the router
316
- */
317
- location: Location;
318
- /**
319
- * The current set of route matches
320
- */
321
- matches: DataRouteMatch[];
322
- /**
323
- * Tracks whether we've completed our initial data load
324
- */
325
- initialized: boolean;
326
- /**
327
- * Tracks whether we should be rendering a HydrateFallback during hydration
328
- */
329
- renderFallback: boolean;
330
- /**
331
- * Current scroll position we should start at for a new view
332
- * - number -> scroll position to restore to
333
- * - false -> do not restore scroll at all (used during submissions/revalidations)
334
- * - null -> don't have a saved position, scroll to hash or top of page
335
- */
336
- restoreScrollPosition: number | false | null;
337
- /**
338
- * Indicate whether this navigation should skip resetting the scroll position
339
- * if we are unable to restore the scroll position
340
- */
341
- preventScrollReset: boolean;
342
- /**
343
- * Tracks the state of the current navigation
344
- */
345
- navigation: Navigation;
346
- /**
347
- * Tracks any in-progress revalidations
348
- */
349
- revalidation: RevalidationState;
350
- /**
351
- * Data from the loaders for the current matches
352
- */
353
- loaderData: RouteData;
354
- /**
355
- * Data from the action for the current matches
356
- */
357
- actionData: RouteData | null;
358
- /**
359
- * Errors caught from loaders for the current matches
360
- */
361
- errors: RouteData | null;
362
- /**
363
- * Map of current fetchers
364
- */
365
- fetchers: Map<string, Fetcher>;
366
- /**
367
- * Map of current blockers
368
- */
369
- blockers: Map<string, Blocker>;
370
- }
371
- /**
372
- * Data that can be passed into hydrate a Router from SSR
373
- */
374
- type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
375
- /**
376
- * Future flags to toggle new feature behavior
377
- */
378
- interface FutureConfig {
379
- }
380
- /**
381
- * Initialization options for createRouter
382
- */
383
- interface RouterInit {
384
- routes: RouteObject[];
385
- history: History;
386
- basename?: string;
387
- getContext?: () => MaybePromise<RouterContextProvider>;
388
- instrumentations?: ClientInstrumentation[];
389
- mapRouteProperties?: MapRoutePropertiesFunction;
390
- future?: Partial<FutureConfig>;
391
- hydrationRouteProperties?: string[];
392
- hydrationData?: HydrationState;
393
- window?: Window;
394
- dataStrategy?: DataStrategyFunction;
395
- patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
396
- }
397
- /**
398
- * State returned from a server-side query() call
399
- */
400
- interface StaticHandlerContext {
401
- basename: Router$1["basename"];
402
- location: RouterState["location"];
403
- matches: RouterState["matches"];
404
- loaderData: RouterState["loaderData"];
405
- actionData: RouterState["actionData"];
406
- errors: RouterState["errors"];
407
- statusCode: number;
408
- loaderHeaders: Record<string, Headers>;
409
- actionHeaders: Record<string, Headers>;
410
- _deepestRenderedBoundaryId?: string | null;
411
- }
412
- /**
413
- * A StaticHandler instance manages a singular SSR navigation/fetch event
414
- */
415
- interface StaticHandler {
416
- /**
417
- * The set of data routes managed by this handler
418
- */
419
- dataRoutes: DataRouteObject[];
420
- /**
421
- * @private
422
- * PRIVATE - DO NOT USE
423
- *
424
- * The route branches derived from the data routes, used for internal route
425
- * matching in Framework Mode
426
- */
427
- _internalRouteBranches: RouteBranch<DataRouteObject>[];
428
- /**
429
- * Perform a query for a given request - executing all matched route
430
- * loaders/actions. Used for document requests.
431
- *
432
- * @param request The request to query
433
- * @param opts Optional query options
434
- * @param opts.dataStrategy Alternate dataStrategy implementation
435
- * @param opts.filterMatchesToLoad Predicate function to filter which matches should be loaded
436
- * @param opts.generateMiddlewareResponse To enable middleware, provide a function
437
- * to generate a response to bubble back up the middleware chain
438
- * @param opts.requestContext Context object to pass to loaders/actions
439
- * @param opts.skipLoaderErrorBubbling Skip loader error bubbling
440
- * @param opts.skipRevalidation Skip revalidation after action submission
441
- * @param opts.normalizePath Normalize the request path
442
- */
443
- query(request: Request, opts?: {
444
- requestContext?: unknown;
445
- filterMatchesToLoad?: (match: DataRouteMatch) => boolean;
446
- skipLoaderErrorBubbling?: boolean;
447
- skipRevalidation?: boolean;
448
- dataStrategy?: DataStrategyFunction<unknown>;
449
- generateMiddlewareResponse?: (query: (r: Request, args?: {
450
- filterMatchesToLoad?: (match: DataRouteMatch) => boolean;
451
- }) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
452
- normalizePath?: (request: Request) => Path;
453
- }): Promise<StaticHandlerContext | Response>;
454
- /**
455
- * Perform a query for a specific route. Used for resource requests.
456
- *
457
- * @param request The request to query
458
- * @param opts Optional queryRoute options
459
- * @param opts.dataStrategy Alternate dataStrategy implementation
460
- * @param opts.generateMiddlewareResponse To enable middleware, provide a function
461
- * to generate a response to bubble back up the middleware chain
462
- * @param opts.requestContext Context object to pass to loaders/actions
463
- * @param opts.routeId The ID of the route to query
464
- * @param opts.normalizePath Normalize the request path
465
-
466
- */
467
- queryRoute(request: Request, opts?: {
468
- routeId?: string;
469
- requestContext?: unknown;
470
- dataStrategy?: DataStrategyFunction<unknown>;
471
- generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
472
- normalizePath?: (request: Request) => Path;
473
- }): Promise<any>;
474
- }
475
- type ViewTransitionOpts = {
476
- currentLocation: Location;
477
- nextLocation: Location;
478
- };
479
- /**
480
- * Subscriber function signature for changes to router state
481
- */
482
- interface RouterSubscriber {
483
- (state: RouterState, opts: {
484
- deletedFetchers: string[];
485
- newErrors: RouteData | null;
486
- viewTransitionOpts?: ViewTransitionOpts;
487
- flushSync: boolean;
488
- }): void;
489
- }
490
- /**
491
- * Function signature for determining the key to be used in scroll restoration
492
- * for a given location
493
- */
494
- interface GetScrollRestorationKeyFunction {
495
- (location: Location, matches: UIMatch[]): string | null;
496
- }
497
- /**
498
- * Function signature for determining the current scroll position
499
- */
500
- interface GetScrollPositionFunction {
501
- (): number;
502
- }
503
- /**
504
- * - "route": relative to the route hierarchy so `..` means remove all segments
505
- * of the current route even if it has many. For example, a `route("posts/:id")`
506
- * would have both `:id` and `posts` removed from the url.
507
- * - "path": relative to the pathname so `..` means remove one segment of the
508
- * pathname. For example, a `route("posts/:id")` would have only `:id` removed
509
- * from the url.
510
- */
511
- type RelativeRoutingType = "route" | "path";
512
- type BaseNavigateOrFetchOptions = {
513
- preventScrollReset?: boolean;
514
- relative?: RelativeRoutingType;
515
- flushSync?: boolean;
516
- defaultShouldRevalidate?: boolean;
517
- };
518
- type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
519
- replace?: boolean;
520
- state?: any;
521
- fromRouteId?: string;
522
- viewTransition?: boolean;
523
- mask?: To;
524
- };
525
- type BaseSubmissionOptions = {
526
- formMethod?: HTMLFormMethod;
527
- formEncType?: FormEncType;
528
- } & ({
529
- formData: FormData;
530
- body?: undefined;
531
- } | {
532
- formData?: undefined;
533
- body: any;
534
- });
535
- /**
536
- * Options for a navigate() call for a normal (non-submission) navigation
537
- */
538
- type LinkNavigateOptions = BaseNavigateOptions;
539
- /**
540
- * Options for a navigate() call for a submission navigation
541
- */
542
- type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
543
- /**
544
- * Options to pass to navigate() for a navigation
545
- */
546
- type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
547
- /**
548
- * Options for a fetch() load
549
- */
550
- type LoadFetchOptions = BaseNavigateOrFetchOptions;
551
- /**
552
- * Options for a fetch() submission
553
- */
554
- type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
555
- /**
556
- * Options to pass to fetch()
557
- */
558
- type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
559
- /**
560
- * Potential states for state.navigation
561
- */
562
- type NavigationStates = {
563
- Idle: {
564
- state: "idle";
565
- location: undefined;
566
- matches: undefined;
567
- historyAction: undefined;
568
- formMethod: undefined;
569
- formAction: undefined;
570
- formEncType: undefined;
571
- formData: undefined;
572
- json: undefined;
573
- text: undefined;
574
- };
575
- Loading: {
576
- state: "loading";
577
- location: Location;
578
- matches: DataRouteMatch[];
579
- historyAction: Action;
580
- formMethod: Submission["formMethod"] | undefined;
581
- formAction: Submission["formAction"] | undefined;
582
- formEncType: Submission["formEncType"] | undefined;
583
- formData: Submission["formData"] | undefined;
584
- json: Submission["json"] | undefined;
585
- text: Submission["text"] | undefined;
586
- };
587
- Submitting: {
588
- state: "submitting";
589
- location: Location;
590
- matches: DataRouteMatch[];
591
- historyAction: Action;
592
- formMethod: Submission["formMethod"];
593
- formAction: Submission["formAction"];
594
- formEncType: Submission["formEncType"];
595
- formData: Submission["formData"];
596
- json: Submission["json"];
597
- text: Submission["text"];
598
- };
599
- };
600
- type Navigation = NavigationStates[keyof NavigationStates];
601
- type RevalidationState = "idle" | "loading";
602
- /**
603
- * Potential states for fetchers
604
- */
605
- type FetcherStates<TData = any> = {
606
- /**
607
- * The fetcher is not calling a loader or action
608
- *
609
- * ```tsx
610
- * fetcher.state === "idle"
611
- * ```
612
- */
613
- Idle: {
614
- state: "idle";
615
- formMethod: undefined;
616
- formAction: undefined;
617
- formEncType: undefined;
618
- text: undefined;
619
- formData: undefined;
620
- json: undefined;
621
- /**
622
- * If the fetcher has never been called, this will be undefined.
623
- */
624
- data: TData | undefined;
625
- };
626
- /**
627
- * The fetcher is loading data from a {@link LoaderFunction | loader} from a
628
- * call to {@link FetcherWithComponents.load | `fetcher.load`}.
629
- *
630
- * ```tsx
631
- * // somewhere
632
- * <button onClick={() => fetcher.load("/some/route") }>Load</button>
633
- *
634
- * // the state will update
635
- * fetcher.state === "loading"
636
- * ```
637
- */
638
- Loading: {
639
- state: "loading";
640
- formMethod: Submission["formMethod"] | undefined;
641
- formAction: Submission["formAction"] | undefined;
642
- formEncType: Submission["formEncType"] | undefined;
643
- text: Submission["text"] | undefined;
644
- formData: Submission["formData"] | undefined;
645
- json: Submission["json"] | undefined;
646
- data: TData | undefined;
647
- };
648
- /**
649
- The fetcher is submitting to a {@link LoaderFunction} (GET) or {@link ActionFunction} (POST) from a {@link FetcherWithComponents.Form | `fetcher.Form`} or {@link FetcherWithComponents.submit | `fetcher.submit`}.
650
-
651
- ```tsx
652
- // somewhere
653
- <input
654
- onChange={e => {
655
- fetcher.submit(event.currentTarget.form, { method: "post" });
656
- }}
657
- />
658
-
659
- // the state will update
660
- fetcher.state === "submitting"
661
-
662
- // and formData will be available
663
- fetcher.formData
664
- ```
665
- */
666
- Submitting: {
667
- state: "submitting";
668
- formMethod: Submission["formMethod"];
669
- formAction: Submission["formAction"];
670
- formEncType: Submission["formEncType"];
671
- text: Submission["text"];
672
- formData: Submission["formData"];
673
- json: Submission["json"];
674
- data: TData | undefined;
675
- };
676
- };
677
- type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
678
- interface BlockerBlocked {
679
- state: "blocked";
680
- reset: () => void;
681
- proceed: () => void;
682
- location: Location;
683
- }
684
- interface BlockerUnblocked {
685
- state: "unblocked";
686
- reset: undefined;
687
- proceed: undefined;
688
- location: undefined;
689
- }
690
- interface BlockerProceeding {
691
- state: "proceeding";
692
- reset: undefined;
693
- proceed: undefined;
694
- location: Location;
695
- }
696
- type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
697
- type BlockerFunction = (args: {
698
- currentLocation: Location;
699
- nextLocation: Location;
700
- historyAction: Action;
701
- }) => boolean;
702
- declare const IDLE_NAVIGATION: NavigationStates["Idle"];
703
- declare const IDLE_FETCHER: FetcherStates["Idle"];
704
- declare const IDLE_BLOCKER: BlockerUnblocked;
705
- /**
706
- * Create a router and listen to history POP navigations
707
- */
708
- declare function createRouter(init: RouterInit): Router$1;
709
- interface CreateStaticHandlerOptions {
710
- basename?: string;
711
- mapRouteProperties?: MapRoutePropertiesFunction;
712
- instrumentations?: Pick<ServerInstrumentation, "route">[];
713
- future?: Partial<FutureConfig>;
714
- }
715
-
716
- declare function mapRouteProperties(route: RouteObject): Partial<RouteObject> & {
717
- hasErrorBoundary: boolean;
718
- };
719
- declare const hydrationRouteProperties: (keyof RouteObject)[];
720
- /**
721
- * @category Data Routers
722
- */
723
- interface MemoryRouterOpts {
724
- /**
725
- * Basename path for the application.
726
- */
727
- basename?: string;
728
- /**
729
- * A function that returns an {@link RouterContextProvider} instance
730
- * which is provided as the `context` argument to client [`action`](../../start/data/route-object#action)s,
731
- * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
732
- * This function is called to generate a fresh `context` instance on each
733
- * navigation or fetcher call.
734
- */
735
- getContext?: RouterInit["getContext"];
736
- /**
737
- * Future flags to enable for the router.
738
- */
739
- future?: Partial<FutureConfig>;
740
- /**
741
- * Hydration data to initialize the router with if you have already performed
742
- * data loading on the server.
743
- */
744
- hydrationData?: HydrationState;
745
- /**
746
- * Initial entries in the in-memory history stack
747
- */
748
- initialEntries?: InitialEntry[];
749
- /**
750
- * Index of `initialEntries` the application should initialize to
751
- */
752
- initialIndex?: number;
753
- /**
754
- * Array of instrumentation objects allowing you to instrument the router and
755
- * individual routes prior to router initialization (and on any subsequently
756
- * added routes via `route.lazy` or `patchRoutesOnNavigation`). This is
757
- * mostly useful for observability such as wrapping navigations, fetches,
758
- * as well as route loaders/actions/middlewares with logging and/or performance
759
- * tracing. See the [docs](../../how-to/instrumentation) for more information.
760
- *
761
- * ```tsx
762
- * let router = createBrowserRouter(routes, {
763
- * instrumentations: [logging]
764
- * });
765
- *
766
- *
767
- * let logging = {
768
- * router({ instrument }) {
769
- * instrument({
770
- * navigate: (impl, info) => logExecution(`navigate ${info.to}`, impl),
771
- * fetch: (impl, info) => logExecution(`fetch ${info.to}`, impl)
772
- * });
773
- * },
774
- * route({ instrument, id }) {
775
- * instrument({
776
- * middleware: (impl, info) => logExecution(
777
- * `middleware ${info.request.url} (route ${id})`,
778
- * impl
779
- * ),
780
- * loader: (impl, info) => logExecution(
781
- * `loader ${info.request.url} (route ${id})`,
782
- * impl
783
- * ),
784
- * action: (impl, info) => logExecution(
785
- * `action ${info.request.url} (route ${id})`,
786
- * impl
787
- * ),
788
- * })
789
- * }
790
- * };
791
- *
792
- * async function logExecution(label: string, impl: () => Promise<void>) {
793
- * let start = performance.now();
794
- * console.log(`start ${label}`);
795
- * await impl();
796
- * let duration = Math.round(performance.now() - start);
797
- * console.log(`end ${label} (${duration}ms)`);
798
- * }
799
- * ```
800
- */
801
- instrumentations?: ClientInstrumentation[];
802
- /**
803
- * Override the default data strategy of running loaders in parallel -
804
- * see the [docs](../../how-to/data-strategy) for more information.
805
- *
806
- * ```tsx
807
- * let router = createBrowserRouter(routes, {
808
- * async dataStrategy({
809
- * matches,
810
- * request,
811
- * runClientMiddleware,
812
- * }) {
813
- * const matchesToLoad = matches.filter((m) =>
814
- * m.shouldCallHandler(),
815
- * );
816
- *
817
- * const results: Record<string, DataStrategyResult> = {};
818
- * await runClientMiddleware(() =>
819
- * Promise.all(
820
- * matchesToLoad.map(async (match) => {
821
- * results[match.route.id] = await match.resolve();
822
- * }),
823
- * ),
824
- * );
825
- * return results;
826
- * },
827
- * });
828
- * ```
829
- */
830
- dataStrategy?: DataStrategyFunction;
831
- /**
832
- * Lazily define portions of the route tree on navigations.
833
- */
834
- patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
835
- }
836
- /**
837
- * Create a new {@link DataRouter} that manages the application path using an
838
- * in-memory [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
839
- * stack. Useful for non-browser environments without a DOM API.
840
- *
841
- * Data Routers should not be held in React state. You should create your router
842
- * once outside of the React tree and pass it to {@link RouterProvider | `<RouterProvider>`}.
843
- * You can use `patchRoutesOnNavigation` to add additional routes programmatically.
844
- *
845
- * @public
846
- * @category Data Routers
847
- * @mode data
848
- * @param routes Application routes
849
- * @param opts Options
850
- * @param {MemoryRouterOpts.basename} opts.basename n/a
851
- * @param {MemoryRouterOpts.dataStrategy} opts.dataStrategy n/a
852
- * @param {MemoryRouterOpts.future} opts.future n/a
853
- * @param {MemoryRouterOpts.getContext} opts.getContext n/a
854
- * @param {MemoryRouterOpts.hydrationData} opts.hydrationData n/a
855
- * @param {MemoryRouterOpts.initialEntries} opts.initialEntries n/a
856
- * @param {MemoryRouterOpts.initialIndex} opts.initialIndex n/a
857
- * @param {MemoryRouterOpts.instrumentations} opts.instrumentations n/a
858
- * @param {MemoryRouterOpts.patchRoutesOnNavigation} opts.patchRoutesOnNavigation n/a
859
- * @returns An initialized {@link DataRouter} to pass to {@link RouterProvider | `<RouterProvider>`}
860
- */
861
- declare function createMemoryRouter(routes: RouteObject[], opts?: MemoryRouterOpts): Router$1;
862
- /**
863
- * Function signature for client side error handling for loader/actions errors
864
- * and rendering errors via `componentDidCatch`
865
- */
866
- interface ClientOnErrorFunction {
867
- (error: unknown, info: {
868
- location: Location;
869
- params: Params;
870
- pattern: string;
871
- errorInfo?: React.ErrorInfo;
872
- }): void;
873
- }
874
- /**
875
- * @category Types
876
- */
877
- interface RouterProviderProps {
878
- /**
879
- * The {@link DataRouter} instance to use for navigation and data fetching. The
880
- * router prop should be a single router instance created outside of the React
881
- * tree. Avoid creating new routers during React renders/re-renders.
882
- */
883
- router: Router$1;
884
- /**
885
- * The [`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync)
886
- * implementation to use for flushing updates.
887
- *
888
- * You usually don't have to worry about this:
889
- * - The `RouterProvider` exported from `react-router/dom` handles this internally for you
890
- * - If you are rendering in a non-DOM environment, you can import
891
- * `RouterProvider` from `react-router` and ignore this prop
892
- */
893
- flushSync?: (fn: () => unknown) => undefined;
894
- /**
895
- * An error handler function that will be called for any middleware, loader, action,
896
- * or render errors that are encountered in your application. This is useful for
897
- * logging or reporting errors instead of in the {@link ErrorBoundary} because it's not
898
- * subject to re-rendering and will only run one time per error.
899
- *
900
- * The `errorInfo` parameter is passed along from
901
- * [`componentDidCatch`](https://react.dev/reference/react/Component#componentdidcatch)
902
- * and is only present for render errors.
903
- *
904
- * ```tsx
905
- * <RouterProvider onError={(error, info) => {
906
- * let { location, params, pattern, errorInfo } = info;
907
- * console.error(error, location, errorInfo);
908
- * reportToErrorService(error, location, errorInfo);
909
- * }} />
910
- * ```
911
- */
912
- onError?: ClientOnErrorFunction;
913
- /**
914
- * Control whether router state updates are internally wrapped in
915
- * [`React.startTransition`](https://react.dev/reference/react/startTransition).
916
- *
917
- * - When left `undefined`, all state updates are wrapped in
918
- * `React.startTransition`
919
- * - This can lead to buggy behaviors if you are wrapping your own
920
- * navigations/fetchers in `startTransition`.
921
- * - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
922
- * in `React.startTransition` and router state changes will be wrapped in
923
- * `React.startTransition` and also sent through
924
- * [`useOptimistic`](https://react.dev/reference/react/useOptimistic) to
925
- * surface mid-navigation router state changes to the UI.
926
- * - When set to `false`, the router will not leverage `React.startTransition` or
927
- * `React.useOptimistic` on any navigations or state changes.
928
- *
929
- * For more information, please see the [docs](../../explanation/react-transitions).
930
- */
931
- useTransitions?: boolean;
932
- }
933
- /**
934
- * Render the UI for the given {@link DataRouter}. This component should
935
- * typically be at the top of an app's element tree. The router prop should
936
- * be a single router instance created outside of the React tree. Avoid
937
- * creating new routers during React renders/re-renders.
938
- *
939
- * ```tsx
940
- * import { createBrowserRouter } from "react-router";
941
- * import { RouterProvider } from "react-router/dom";
942
- * import { createRoot } from "react-dom/client";
943
- *
944
- * const router = createBrowserRouter(routes);
945
- * createRoot(document.getElementById("root")).render(
946
- * <RouterProvider router={router} />
947
- * );
948
- * ```
949
- *
950
- * <docs-info>Please note that this component is exported both from
951
- * `react-router` and `react-router/dom` with the only difference being that the
952
- * latter automatically wires up `react-dom`'s [`flushSync`](https://react.dev/reference/react-dom/flushSync)
953
- * implementation. You _almost always_ want to use the version from
954
- * `react-router/dom` unless you're running in a non-DOM environment.</docs-info>
955
- *
956
- *
957
- * @public
958
- * @category Data Routers
959
- * @mode data
960
- * @param props Props
961
- * @param {RouterProviderProps.flushSync} props.flushSync n/a
962
- * @param {RouterProviderProps.onError} props.onError n/a
963
- * @param {RouterProviderProps.router} props.router n/a
964
- * @param {RouterProviderProps.useTransitions} props.useTransitions n/a
965
- * @returns React element for the rendered router
966
- */
967
- declare function RouterProvider({ router, flushSync: reactDomFlushSyncImpl, onError, useTransitions, }: RouterProviderProps): React.ReactElement;
968
- /**
969
- * @category Types
970
- */
971
- interface MemoryRouterProps {
972
- /**
973
- * Application basename
974
- */
975
- basename?: string;
976
- /**
977
- * Nested {@link Route} elements describing the route tree
978
- */
979
- children?: React.ReactNode;
980
- /**
981
- * Initial entries in the in-memory history stack
982
- */
983
- initialEntries?: InitialEntry[];
984
- /**
985
- * Index of `initialEntries` the application should initialize to
986
- */
987
- initialIndex?: number;
988
- /**
989
- * Control whether router state updates are internally wrapped in
990
- * [`React.startTransition`](https://react.dev/reference/react/startTransition).
991
- *
992
- * - When left `undefined`, all router state updates are wrapped in
993
- * `React.startTransition`
994
- * - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
995
- * in `React.startTransition` and all router state updates are wrapped in
996
- * `React.startTransition`
997
- * - When set to `false`, the router will not leverage `React.startTransition`
998
- * on any navigations or state changes.
999
- *
1000
- * For more information, please see the [docs](../../explanation/react-transitions).
1001
- */
1002
- useTransitions?: boolean;
1003
- }
1004
- /**
1005
- * A declarative {@link Router | `<Router>`} that stores all entries in memory.
1006
- *
1007
- * @public
1008
- * @category Declarative Routers
1009
- * @mode declarative
1010
- * @param props Props
1011
- * @param {MemoryRouterProps.basename} props.basename n/a
1012
- * @param {MemoryRouterProps.children} props.children n/a
1013
- * @param {MemoryRouterProps.initialEntries} props.initialEntries n/a
1014
- * @param {MemoryRouterProps.initialIndex} props.initialIndex n/a
1015
- * @param {MemoryRouterProps.useTransitions} props.useTransitions n/a
1016
- * @returns A declarative in-memory {@link Router | `<Router>`} for client-side
1017
- * routing.
1018
- */
1019
- declare function MemoryRouter({ basename, children, initialEntries, initialIndex, useTransitions, }: MemoryRouterProps): React.ReactElement;
1020
- /**
1021
- * @category Types
1022
- */
1023
- interface NavigateProps {
1024
- /**
1025
- * The path to navigate to. This can be a string or a {@link Path} object
1026
- */
1027
- to: To;
1028
- /**
1029
- * Whether to replace the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
1030
- * stack
1031
- */
1032
- replace?: boolean;
1033
- /**
1034
- * State to pass to the new {@link Location} to store in [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state).
1035
- */
1036
- state?: any;
1037
- /**
1038
- * How to interpret relative routing in the `to` prop.
1039
- * See {@link RelativeRoutingType}.
1040
- */
1041
- relative?: RelativeRoutingType;
1042
- }
1043
- /**
1044
- * A component-based version of {@link useNavigate} to use in a
1045
- * [`React.Component` class](https://react.dev/reference/react/Component) where
1046
- * hooks cannot be used.
1047
- *
1048
- * It's recommended to avoid using this component in favor of {@link useNavigate}.
1049
- *
1050
- * @example
1051
- * <Navigate to="/tasks" />
1052
- *
1053
- * @public
1054
- * @category Components
1055
- * @param props Props
1056
- * @param {NavigateProps.relative} props.relative n/a
1057
- * @param {NavigateProps.replace} props.replace n/a
1058
- * @param {NavigateProps.state} props.state n/a
1059
- * @param {NavigateProps.to} props.to n/a
1060
- * @returns {void}
1061
- *
1062
- */
1063
- declare function Navigate({ to, replace, state, relative, }: NavigateProps): null;
1064
- /**
1065
- * @category Types
1066
- */
1067
- interface OutletProps {
1068
- /**
1069
- * Provides a context value to the element tree below the outlet. Use when
1070
- * the parent route needs to provide values to child routes.
1071
- *
1072
- * ```tsx
1073
- * <Outlet context={myContextValue} />
1074
- * ```
1075
- *
1076
- * Access the context with {@link useOutletContext}.
1077
- */
1078
- context?: unknown;
1079
- }
1080
- /**
1081
- * Renders the matching child route of a parent route or nothing if no child
1082
- * route matches.
1083
- *
1084
- * @example
1085
- * import { Outlet } from "react-router";
1086
- *
1087
- * export default function SomeParent() {
1088
- * return (
1089
- * <div>
1090
- * <h1>Parent Content</h1>
1091
- * <Outlet />
1092
- * </div>
1093
- * );
1094
- * }
1095
- *
1096
- * @public
1097
- * @category Components
1098
- * @param props Props
1099
- * @param {OutletProps.context} props.context n/a
1100
- * @returns React element for the rendered outlet or `null` if no child route matches.
1101
- */
1102
- declare function Outlet(props: OutletProps): React.ReactElement | null;
1103
- /**
1104
- * @category Types
1105
- */
1106
- interface PathRouteProps {
1107
- /**
1108
- * Whether the path should be case-sensitive. Defaults to `false`.
1109
- */
1110
- caseSensitive?: NonIndexRouteObject["caseSensitive"];
1111
- /**
1112
- * The path pattern to match. If unspecified or empty, then this becomes a
1113
- * layout route.
1114
- */
1115
- path?: NonIndexRouteObject["path"];
1116
- /**
1117
- * The unique identifier for this route (for use with {@link DataRouter}s)
1118
- */
1119
- id?: NonIndexRouteObject["id"];
1120
- /**
1121
- * A function that returns a promise that resolves to the route object.
1122
- * Used for code-splitting routes.
1123
- * See [`lazy`](../../start/data/route-object#lazy).
1124
- */
1125
- lazy?: LazyRouteFunction<NonIndexRouteObject>;
1126
- /**
1127
- * The route middleware.
1128
- * See [`middleware`](../../start/data/route-object#middleware).
1129
- */
1130
- middleware?: NonIndexRouteObject["middleware"];
1131
- /**
1132
- * The route loader.
1133
- * See [`loader`](../../start/data/route-object#loader).
1134
- */
1135
- loader?: NonIndexRouteObject["loader"];
1136
- /**
1137
- * The route action.
1138
- * See [`action`](../../start/data/route-object#action).
1139
- */
1140
- action?: NonIndexRouteObject["action"];
1141
- hasErrorBoundary?: NonIndexRouteObject["hasErrorBoundary"];
1142
- /**
1143
- * The route shouldRevalidate function.
1144
- * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
1145
- */
1146
- shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
1147
- /**
1148
- * The route handle.
1149
- */
1150
- handle?: NonIndexRouteObject["handle"];
1151
- /**
1152
- * Whether this is an index route.
1153
- */
1154
- index?: false;
1155
- /**
1156
- * Child Route components
1157
- */
1158
- children?: React.ReactNode;
1159
- /**
1160
- * The React element to render when this Route matches.
1161
- * Mutually exclusive with `Component`.
1162
- */
1163
- element?: React.ReactNode | null;
1164
- /**
1165
- * The React element to render while this router is loading data.
1166
- * Mutually exclusive with `HydrateFallback`.
1167
- */
1168
- hydrateFallbackElement?: React.ReactNode | null;
1169
- /**
1170
- * The React element to render at this route if an error occurs.
1171
- * Mutually exclusive with `ErrorBoundary`.
1172
- */
1173
- errorElement?: React.ReactNode | null;
1174
- /**
1175
- * The React Component to render when this route matches.
1176
- * Mutually exclusive with `element`.
1177
- */
1178
- Component?: React.ComponentType | null;
1179
- /**
1180
- * The React Component to render while this router is loading data.
1181
- * Mutually exclusive with `hydrateFallbackElement`.
1182
- */
1183
- HydrateFallback?: React.ComponentType | null;
1184
- /**
1185
- * The React Component to render at this route if an error occurs.
1186
- * Mutually exclusive with `errorElement`.
1187
- */
1188
- ErrorBoundary?: React.ComponentType | null;
1189
- }
1190
- /**
1191
- * @category Types
1192
- */
1193
- interface LayoutRouteProps extends PathRouteProps {
1194
- }
1195
- /**
1196
- * @category Types
1197
- */
1198
- interface IndexRouteProps {
1199
- /**
1200
- * Whether the path should be case-sensitive. Defaults to `false`.
1201
- */
1202
- caseSensitive?: IndexRouteObject["caseSensitive"];
1203
- /**
1204
- * The path pattern to match. If unspecified or empty, then this becomes a
1205
- * layout route.
1206
- */
1207
- path?: IndexRouteObject["path"];
1208
- /**
1209
- * The unique identifier for this route (for use with {@link DataRouter}s)
1210
- */
1211
- id?: IndexRouteObject["id"];
1212
- /**
1213
- * A function that returns a promise that resolves to the route object.
1214
- * Used for code-splitting routes.
1215
- * See [`lazy`](../../start/data/route-object#lazy).
1216
- */
1217
- lazy?: LazyRouteFunction<IndexRouteObject>;
1218
- /**
1219
- * The route middleware.
1220
- * See [`middleware`](../../start/data/route-object#middleware).
1221
- */
1222
- middleware?: IndexRouteObject["middleware"];
1223
- /**
1224
- * The route loader.
1225
- * See [`loader`](../../start/data/route-object#loader).
1226
- */
1227
- loader?: IndexRouteObject["loader"];
1228
- /**
1229
- * The route action.
1230
- * See [`action`](../../start/data/route-object#action).
1231
- */
1232
- action?: IndexRouteObject["action"];
1233
- hasErrorBoundary?: IndexRouteObject["hasErrorBoundary"];
1234
- /**
1235
- * The route shouldRevalidate function.
1236
- * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
1237
- */
1238
- shouldRevalidate?: IndexRouteObject["shouldRevalidate"];
1239
- /**
1240
- * The route handle.
1241
- */
1242
- handle?: IndexRouteObject["handle"];
1243
- /**
1244
- * Whether this is an index route.
1245
- */
1246
- index: true;
1247
- /**
1248
- * Child Route components
1249
- */
1250
- children?: undefined;
1251
- /**
1252
- * The React element to render when this Route matches.
1253
- * Mutually exclusive with `Component`.
1254
- */
1255
- element?: React.ReactNode | null;
1256
- /**
1257
- * The React element to render while this router is loading data.
1258
- * Mutually exclusive with `HydrateFallback`.
1259
- */
1260
- hydrateFallbackElement?: React.ReactNode | null;
1261
- /**
1262
- * The React element to render at this route if an error occurs.
1263
- * Mutually exclusive with `ErrorBoundary`.
1264
- */
1265
- errorElement?: React.ReactNode | null;
1266
- /**
1267
- * The React Component to render when this route matches.
1268
- * Mutually exclusive with `element`.
1269
- */
1270
- Component?: React.ComponentType | null;
1271
- /**
1272
- * The React Component to render while this router is loading data.
1273
- * Mutually exclusive with `hydrateFallbackElement`.
1274
- */
1275
- HydrateFallback?: React.ComponentType | null;
1276
- /**
1277
- * The React Component to render at this route if an error occurs.
1278
- * Mutually exclusive with `errorElement`.
1279
- */
1280
- ErrorBoundary?: React.ComponentType | null;
1281
- }
1282
- /**
1283
- * @category Types
1284
- */
1285
- type RouteProps = PathRouteProps | LayoutRouteProps | IndexRouteProps;
1286
- /**
1287
- * Configures an element to render when a pattern matches the current location.
1288
- * It must be rendered within a {@link Routes} element. Note that these routes
1289
- * do not participate in data loading, actions, code splitting, or any other
1290
- * route module features.
1291
- *
1292
- * @example
1293
- * // Usually used in a declarative router
1294
- * function App() {
1295
- * return (
1296
- * <BrowserRouter>
1297
- * <Routes>
1298
- * <Route index element={<StepOne />} />
1299
- * <Route path="step-2" element={<StepTwo />} />
1300
- * <Route path="step-3" element={<StepThree />} />
1301
- * </Routes>
1302
- * </BrowserRouter>
1303
- * );
1304
- * }
1305
- *
1306
- * // But can be used with a data router as well if you prefer the JSX notation
1307
- * const routes = createRoutesFromElements(
1308
- * <>
1309
- * <Route index loader={step1Loader} Component={StepOne} />
1310
- * <Route path="step-2" loader={step2Loader} Component={StepTwo} />
1311
- * <Route path="step-3" loader={step3Loader} Component={StepThree} />
1312
- * </>
1313
- * );
1314
- *
1315
- * const router = createBrowserRouter(routes);
1316
- *
1317
- * function App() {
1318
- * return <RouterProvider router={router} />;
1319
- * }
1320
- *
1321
- * @public
1322
- * @category Components
1323
- * @param props Props
1324
- * @param {PathRouteProps.action} props.action n/a
1325
- * @param {PathRouteProps.caseSensitive} props.caseSensitive n/a
1326
- * @param {PathRouteProps.Component} props.Component n/a
1327
- * @param {PathRouteProps.children} props.children n/a
1328
- * @param {PathRouteProps.element} props.element n/a
1329
- * @param {PathRouteProps.ErrorBoundary} props.ErrorBoundary n/a
1330
- * @param {PathRouteProps.errorElement} props.errorElement n/a
1331
- * @param {PathRouteProps.handle} props.handle n/a
1332
- * @param {PathRouteProps.HydrateFallback} props.HydrateFallback n/a
1333
- * @param {PathRouteProps.hydrateFallbackElement} props.hydrateFallbackElement n/a
1334
- * @param {PathRouteProps.id} props.id n/a
1335
- * @param {PathRouteProps.index} props.index n/a
1336
- * @param {PathRouteProps.lazy} props.lazy n/a
1337
- * @param {PathRouteProps.loader} props.loader n/a
1338
- * @param {PathRouteProps.path} props.path n/a
1339
- * @param {PathRouteProps.shouldRevalidate} props.shouldRevalidate n/a
1340
- * @returns {void}
1341
- */
1342
- declare function Route(props: RouteProps): React.ReactElement | null;
1343
- /**
1344
- * @category Types
1345
- */
1346
- interface RouterProps {
1347
- /**
1348
- * The base path for the application. This is prepended to all locations
1349
- */
1350
- basename?: string;
1351
- /**
1352
- * Nested {@link Route} elements describing the route tree
1353
- */
1354
- children?: React.ReactNode;
1355
- /**
1356
- * The location to match against. Defaults to the current location.
1357
- * This can be a string or a {@link Location} object.
1358
- */
1359
- location: Partial<Location> | string;
1360
- /**
1361
- * The type of navigation that triggered this `location` change.
1362
- * Defaults to {@link NavigationType.Pop}.
1363
- */
1364
- navigationType?: Action;
1365
- /**
1366
- * The navigator to use for navigation. This is usually a history object
1367
- * or a custom navigator that implements the {@link Navigator} interface.
1368
- */
1369
- navigator: Navigator;
1370
- /**
1371
- * Whether this router is static or not (used for SSR). If `true`, the router
1372
- * will not be reactive to location changes.
1373
- */
1374
- static?: boolean;
1375
- /**
1376
- * Control whether router state updates are internally wrapped in
1377
- * [`React.startTransition`](https://react.dev/reference/react/startTransition).
1378
- *
1379
- * - When left `undefined`, all router state updates are wrapped in
1380
- * `React.startTransition`
1381
- * - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
1382
- * in `React.startTransition` and all router state updates are wrapped in
1383
- * `React.startTransition`
1384
- * - When set to `false`, the router will not leverage `React.startTransition`
1385
- * on any navigations or state changes.
1386
- *
1387
- * For more information, please see the [docs](../../explanation/react-transitions).
1388
- */
1389
- useTransitions?: boolean;
1390
- }
1391
- /**
1392
- * Provides location context for the rest of the app.
1393
- *
1394
- * Note: You usually won't render a `<Router>` directly. Instead, you'll render a
1395
- * router that is more specific to your environment such as a {@link BrowserRouter}
1396
- * in web browsers or a {@link ServerRouter} for server rendering.
1397
- *
1398
- * @public
1399
- * @category Declarative Routers
1400
- * @mode declarative
1401
- * @param props Props
1402
- * @param {RouterProps.basename} props.basename n/a
1403
- * @param {RouterProps.children} props.children n/a
1404
- * @param {RouterProps.location} props.location n/a
1405
- * @param {RouterProps.navigationType} props.navigationType n/a
1406
- * @param {RouterProps.navigator} props.navigator n/a
1407
- * @param {RouterProps.static} props.static n/a
1408
- * @param {RouterProps.useTransitions} props.useTransitions n/a
1409
- * @returns React element for the rendered router or `null` if the location does
1410
- * not match the {@link props.basename}
1411
- */
1412
- declare function Router({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp, useTransitions, }: RouterProps): React.ReactElement | null;
1413
- /**
1414
- * @category Types
1415
- */
1416
- interface RoutesProps {
1417
- /**
1418
- * Nested {@link Route} elements
1419
- */
1420
- children?: React.ReactNode;
1421
- /**
1422
- * The {@link Location} to match against. Defaults to the current location.
1423
- */
1424
- location?: Partial<Location> | string;
1425
- }
1426
- /**
1427
- * Renders a branch of {@link Route | `<Route>`s} that best matches the current
1428
- * location. Note that these routes do not participate in [data loading](../../start/framework/route-module#loader),
1429
- * [`action`](../../start/framework/route-module#action), code splitting, or
1430
- * any other [route module](../../start/framework/route-module) features.
1431
- *
1432
- * @example
1433
- * import { Route, Routes } from "react-router";
1434
- *
1435
- * <Routes>
1436
- * <Route index element={<StepOne />} />
1437
- * <Route path="step-2" element={<StepTwo />} />
1438
- * <Route path="step-3" element={<StepThree />} />
1439
- * </Routes>
1440
- *
1441
- * @public
1442
- * @category Components
1443
- * @param props Props
1444
- * @param {RoutesProps.children} props.children n/a
1445
- * @param {RoutesProps.location} props.location n/a
1446
- * @returns React element for the rendered routes or `null` if no route matches
1447
- */
1448
- declare function Routes({ children, location, }: RoutesProps): React.ReactElement | null;
1449
- interface AwaitResolveRenderFunction<Resolve = any> {
1450
- (data: Awaited<Resolve>): React.ReactNode;
1451
- }
1452
- /**
1453
- * @category Types
1454
- */
1455
- interface AwaitProps<Resolve> {
1456
- /**
1457
- * When using a function, the resolved value is provided as the parameter.
1458
- *
1459
- * ```tsx [2]
1460
- * <Await resolve={reviewsPromise}>
1461
- * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
1462
- * </Await>
1463
- * ```
1464
- *
1465
- * When using React elements, {@link useAsyncValue} will provide the
1466
- * resolved value:
1467
- *
1468
- * ```tsx [2]
1469
- * <Await resolve={reviewsPromise}>
1470
- * <Reviews />
1471
- * </Await>
1472
- *
1473
- * function Reviews() {
1474
- * const resolvedReviews = useAsyncValue();
1475
- * return <div>...</div>;
1476
- * }
1477
- * ```
1478
- */
1479
- children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
1480
- /**
1481
- * The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
1482
- * rejects.
1483
- *
1484
- * ```tsx
1485
- * <Await
1486
- * errorElement={<div>Oops</div>}
1487
- * resolve={reviewsPromise}
1488
- * >
1489
- * <Reviews />
1490
- * </Await>
1491
- * ```
1492
- *
1493
- * To provide a more contextual error, you can use the {@link useAsyncError} in a
1494
- * child component
1495
- *
1496
- * ```tsx
1497
- * <Await
1498
- * errorElement={<ReviewsError />}
1499
- * resolve={reviewsPromise}
1500
- * >
1501
- * <Reviews />
1502
- * </Await>
1503
- *
1504
- * function ReviewsError() {
1505
- * const error = useAsyncError();
1506
- * return <div>Error loading reviews: {error.message}</div>;
1507
- * }
1508
- * ```
1509
- *
1510
- * If you do not provide an `errorElement`, the rejected value will bubble up
1511
- * to the nearest route-level [`ErrorBoundary`](../../start/framework/route-module#errorboundary)
1512
- * and be accessible via the {@link useRouteError} hook.
1513
- */
1514
- errorElement?: React.ReactNode;
1515
- /**
1516
- * Takes a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
1517
- * returned from a [`loader`](../../start/framework/route-module#loader) to be
1518
- * resolved and rendered.
1519
- *
1520
- * ```tsx
1521
- * import { Await, useLoaderData } from "react-router";
1522
- *
1523
- * export async function loader() {
1524
- * let reviews = getReviews(); // not awaited
1525
- * let book = await getBook();
1526
- * return {
1527
- * book,
1528
- * reviews, // this is a promise
1529
- * };
1530
- * }
1531
- *
1532
- * export default function Book() {
1533
- * const {
1534
- * book,
1535
- * reviews, // this is the same promise
1536
- * } = useLoaderData();
1537
- *
1538
- * return (
1539
- * <div>
1540
- * <h1>{book.title}</h1>
1541
- * <p>{book.description}</p>
1542
- * <React.Suspense fallback={<ReviewsSkeleton />}>
1543
- * <Await
1544
- * // and is the promise we pass to Await
1545
- * resolve={reviews}
1546
- * >
1547
- * <Reviews />
1548
- * </Await>
1549
- * </React.Suspense>
1550
- * </div>
1551
- * );
1552
- * }
1553
- * ```
1554
- */
1555
- resolve: Resolve;
1556
- }
1557
- /**
1558
- * Used to render promise values with automatic error handling.
1559
- *
1560
- * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
1561
- *
1562
- * @example
1563
- * import { Await, useLoaderData } from "react-router";
1564
- *
1565
- * export async function loader() {
1566
- * // not awaited
1567
- * const reviews = getReviews();
1568
- * // awaited (blocks the transition)
1569
- * const book = await fetch("/api/book").then((res) => res.json());
1570
- * return { book, reviews };
1571
- * }
1572
- *
1573
- * function Book() {
1574
- * const { book, reviews } = useLoaderData();
1575
- * return (
1576
- * <div>
1577
- * <h1>{book.title}</h1>
1578
- * <p>{book.description}</p>
1579
- * <React.Suspense fallback={<ReviewsSkeleton />}>
1580
- * <Await
1581
- * resolve={reviews}
1582
- * errorElement={
1583
- * <div>Could not load reviews 😬</div>
1584
- * }
1585
- * children={(resolvedReviews) => (
1586
- * <Reviews items={resolvedReviews} />
1587
- * )}
1588
- * />
1589
- * </React.Suspense>
1590
- * </div>
1591
- * );
1592
- * }
1593
- *
1594
- * @public
1595
- * @category Components
1596
- * @mode framework
1597
- * @mode data
1598
- * @param props Props
1599
- * @param {AwaitProps.children} props.children n/a
1600
- * @param {AwaitProps.errorElement} props.errorElement n/a
1601
- * @param {AwaitProps.resolve} props.resolve n/a
1602
- * @returns React element for the rendered awaited value
1603
- */
1604
- declare function Await<Resolve>({ children, errorElement, resolve, }: AwaitProps<Resolve>): React.JSX.Element;
1605
- /**
1606
- * Creates a route config from a React "children" object, which is usually
1607
- * either a `<Route>` element or an array of them. Used internally by
1608
- * `<Routes>` to create a route config from its children.
1609
- *
1610
- * @category Utils
1611
- * @mode data
1612
- * @param children The React children to convert into a route config
1613
- * @param parentPath The path of the parent route, used to generate unique IDs.
1614
- * @returns An array of {@link RouteObject}s that can be used with a {@link DataRouter}
1615
- */
1616
- declare function createRoutesFromChildren(children: React.ReactNode, parentPath?: number[]): RouteObject[];
1617
- /**
1618
- * Create route objects from JSX elements instead of arrays of objects.
1619
- *
1620
- * @example
1621
- * const routes = createRoutesFromElements(
1622
- * <>
1623
- * <Route index loader={step1Loader} Component={StepOne} />
1624
- * <Route path="step-2" loader={step2Loader} Component={StepTwo} />
1625
- * <Route path="step-3" loader={step3Loader} Component={StepThree} />
1626
- * </>
1627
- * );
1628
- *
1629
- * const router = createBrowserRouter(routes);
1630
- *
1631
- * function App() {
1632
- * return <RouterProvider router={router} />;
1633
- * }
1634
- *
1635
- * @name createRoutesFromElements
1636
- * @public
1637
- * @category Utils
1638
- * @mode data
1639
- * @param children The React children to convert into a route config
1640
- * @param parentPath The path of the parent route, used to generate unique IDs.
1641
- * This is used for internal recursion and is not intended to be used by the
1642
- * application developer.
1643
- * @returns An array of {@link RouteObject}s that can be used with a {@link DataRouter}
1644
- */
1645
- declare const createRoutesFromElements: typeof createRoutesFromChildren;
1646
- /**
1647
- * Renders the result of {@link matchRoutes} into a React element.
1648
- *
1649
- * @public
1650
- * @category Utils
1651
- * @param matches The array of {@link RouteMatch | route matches} to render
1652
- * @returns A React element that renders the matched routes or `null` if no matches
1653
- */
1654
- declare function renderMatches(matches: RouteMatch[] | null): React.ReactElement | null;
1655
- declare function useRouteComponentProps(): {
1656
- params: Readonly<Params<string>>;
1657
- loaderData: any;
1658
- actionData: any;
1659
- matches: UIMatch<unknown, unknown>[];
1660
- };
1661
- type RouteComponentProps = ReturnType<typeof useRouteComponentProps>;
1662
- type RouteComponentType = React.ComponentType<RouteComponentProps>;
1663
- declare function WithComponentProps({ children, }: {
1664
- children: React.ReactElement;
1665
- }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
1666
- declare function withComponentProps(Component: RouteComponentType): () => React.ReactElement<{
1667
- params: Readonly<Params<string>>;
1668
- loaderData: any;
1669
- actionData: any;
1670
- matches: UIMatch<unknown, unknown>[];
1671
- }, string | React.JSXElementConstructor<any>>;
1672
- declare function useHydrateFallbackProps(): {
1673
- params: Readonly<Params<string>>;
1674
- loaderData: any;
1675
- actionData: any;
1676
- };
1677
- type HydrateFallbackProps = ReturnType<typeof useHydrateFallbackProps>;
1678
- type HydrateFallbackType = React.ComponentType<HydrateFallbackProps>;
1679
- declare function WithHydrateFallbackProps({ children, }: {
1680
- children: React.ReactElement;
1681
- }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
1682
- declare function withHydrateFallbackProps(HydrateFallback: HydrateFallbackType): () => React.ReactElement<{
1683
- params: Readonly<Params<string>>;
1684
- loaderData: any;
1685
- actionData: any;
1686
- }, string | React.JSXElementConstructor<any>>;
1687
- declare function useErrorBoundaryProps(): {
1688
- params: Readonly<Params<string>>;
1689
- loaderData: any;
1690
- actionData: any;
1691
- error: unknown;
1692
- };
1693
- type ErrorBoundaryProps = ReturnType<typeof useErrorBoundaryProps>;
1694
- type ErrorBoundaryType = React.ComponentType<ErrorBoundaryProps>;
1695
- declare function WithErrorBoundaryProps({ children, }: {
1696
- children: React.ReactElement;
1697
- }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
1698
- declare function withErrorBoundaryProps(ErrorBoundary: ErrorBoundaryType): () => React.ReactElement<{
1699
- params: Readonly<Params<string>>;
1700
- loaderData: any;
1701
- actionData: any;
1702
- error: unknown;
1703
- }, string | React.JSXElementConstructor<any>>;
1704
-
1705
- interface DataRouterContextObject extends Omit<NavigationContextObject, "future" | "useTransitions"> {
1706
- router: Router$1;
1707
- staticContext?: StaticHandlerContext;
1708
- onError?: ClientOnErrorFunction;
1709
- }
1710
- declare const DataRouterContext: React.Context<DataRouterContextObject | null>;
1711
- declare const DataRouterStateContext: React.Context<RouterState | null>;
1712
- type ViewTransitionContextObject = {
1713
- isTransitioning: false;
1714
- } | {
1715
- isTransitioning: true;
1716
- flushSync: boolean;
1717
- currentLocation: Location;
1718
- nextLocation: Location;
1719
- };
1720
- declare const ViewTransitionContext: React.Context<ViewTransitionContextObject>;
1721
- type FetchersContextObject = Map<string, any>;
1722
- declare const FetchersContext: React.Context<FetchersContextObject>;
1723
- declare const AwaitContext: React.Context<TrackedPromise | null>;
1724
- declare const AwaitContextProvider: (props: React.ComponentProps<typeof AwaitContext.Provider>) => React.FunctionComponentElement<React.ProviderProps<TrackedPromise | null>>;
1725
- interface NavigateOptions {
1726
- /** Replace the current entry in the history stack instead of pushing a new one */
1727
- replace?: boolean;
1728
- /** Masked URL */
1729
- mask?: To;
1730
- /** Adds persistent client side routing state to the next location */
1731
- state?: any;
1732
- /** If you are using {@link ScrollRestoration `<ScrollRestoration>`}, prevent the scroll position from being reset to the top of the window when navigating */
1733
- preventScrollReset?: boolean;
1734
- /** Defines the relative path behavior for the link. "route" will use the route hierarchy so ".." will remove all URL segments of the current route pattern while "path" will use the URL path so ".." will remove one URL segment. */
1735
- relative?: RelativeRoutingType;
1736
- /** Wraps the initial state update for this navigation in a {@link https://react.dev/reference/react-dom/flushSync ReactDOM.flushSync} call instead of the default {@link https://react.dev/reference/react/startTransition React.startTransition} */
1737
- flushSync?: boolean;
1738
- /** Enables a {@link https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API View Transition} for this navigation by wrapping the final state update in `document.startViewTransition()`. If you need to apply specific styles for this view transition, you will also need to leverage the {@link useViewTransitionState `useViewTransitionState()`} hook. */
1739
- viewTransition?: boolean;
1740
- /** Specifies the default revalidation behavior after this submission */
1741
- defaultShouldRevalidate?: boolean;
1742
- }
1743
- /**
1744
- * A Navigator is a "location changer"; it's how you get to different locations.
1745
- *
1746
- * Every history instance conforms to the Navigator interface, but the
1747
- * distinction is useful primarily when it comes to the low-level `<Router>` API
1748
- * where both the location and a navigator must be provided separately in order
1749
- * to avoid "tearing" that may occur in a suspense-enabled app if the action
1750
- * and/or location were to be read directly from the history instance.
1751
- */
1752
- interface Navigator {
1753
- createHref: History["createHref"];
1754
- encodeLocation?: History["encodeLocation"];
1755
- go: History["go"];
1756
- push(to: To, state?: any, opts?: NavigateOptions): void;
1757
- replace(to: To, state?: any, opts?: NavigateOptions): void;
1758
- }
1759
- interface NavigationContextObject {
1760
- basename: string;
1761
- navigator: Navigator;
1762
- static: boolean;
1763
- useTransitions: boolean | undefined;
1764
- future: {};
1765
- }
1766
- declare const NavigationContext: React.Context<NavigationContextObject>;
1767
- interface LocationContextObject {
1768
- location: Location;
1769
- navigationType: Action;
1770
- }
1771
- declare const LocationContext: React.Context<LocationContextObject>;
1772
- interface RouteContextObject {
1773
- outlet: React.ReactElement | null;
1774
- matches: RouteMatch[];
1775
- isDataRoute: boolean;
1776
- }
1777
- declare const RouteContext: React.Context<RouteContextObject>;
1778
-
1779
- export { createRoutesFromElements as $, AwaitContextProvider as A, type BlockerFunction as B, type ClientInstrumentation as C, type RouteProps as D, type RouterProps as E, type Fetcher as F, type GetScrollPositionFunction as G, type HydrationState as H, type InstrumentRequestHandlerFunction as I, type RoutesProps as J, Await as K, type LayoutRouteProps as L, type MemoryRouterOpts as M, type NavigateOptions as N, type OutletProps as O, type PathRouteProps as P, MemoryRouter as Q, type RouterInit as R, type StaticHandler as S, Navigate as T, Outlet as U, Route as V, Router as W, RouterProvider as X, Routes as Y, createMemoryRouter as Z, createRoutesFromChildren as _, type RouterProviderProps as a, renderMatches as a0, createRouter as a1, DataRouterContext as a2, DataRouterStateContext as a3, FetchersContext as a4, LocationContext as a5, NavigationContext as a6, RouteContext as a7, ViewTransitionContext as a8, hydrationRouteProperties as a9, mapRouteProperties as aa, WithComponentProps as ab, withComponentProps as ac, WithHydrateFallbackProps as ad, withHydrateFallbackProps as ae, WithErrorBoundaryProps as af, withErrorBoundaryProps as ag, type FutureConfig as ah, type CreateStaticHandlerOptions as ai, type ClientOnErrorFunction as b, type Router$1 as c, type NavigationStates as d, type Blocker as e, type RelativeRoutingType as f, type GetScrollRestorationKeyFunction as g, type StaticHandlerContext as h, type Navigation as i, type RouterState as j, type RouterSubscriber as k, type RouterNavigateOptions as l, type RouterFetchOptions as m, type RevalidationState as n, type ServerInstrumentation as o, type InstrumentRouterFunction as p, type InstrumentRouteFunction as q, type InstrumentationHandlerResult as r, IDLE_NAVIGATION as s, IDLE_FETCHER as t, IDLE_BLOCKER as u, type Navigator as v, type AwaitProps as w, type IndexRouteProps as x, type MemoryRouterProps as y, type NavigateProps as z };