react-router 7.15.1 → 8.0.0-pre.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 (369) hide show
  1. package/CHANGELOG.md +18 -2
  2. package/dist/development/dom-export.d.ts +6 -172
  3. package/dist/development/dom-export.js +12 -1007
  4. package/dist/development/index-react-server-client.d.ts +7 -4
  5. package/dist/development/index-react-server-client.js +8 -52
  6. package/dist/development/index-react-server.d.ts +1645 -1635
  7. package/dist/development/index-react-server.js +2880 -3642
  8. package/dist/development/index.d.ts +43 -1469
  9. package/dist/development/index.js +37 -2621
  10. package/dist/development/lib/actions.js +62 -0
  11. package/dist/development/lib/components.d.ts +1022 -0
  12. package/dist/development/lib/components.js +835 -0
  13. package/dist/development/lib/context.d.ts +83 -0
  14. package/dist/development/lib/context.js +41 -0
  15. package/dist/development/lib/dom/dom.d.ts +119 -0
  16. package/dist/development/lib/dom/dom.js +143 -0
  17. package/dist/development/lib/dom/lib.d.ts +2042 -0
  18. package/dist/development/lib/dom/lib.js +1259 -0
  19. package/dist/development/lib/dom/server.d.ts +138 -0
  20. package/dist/development/lib/dom/server.js +301 -0
  21. package/dist/development/lib/dom/ssr/components.d.ts +196 -0
  22. package/dist/development/lib/dom/ssr/components.js +579 -0
  23. package/dist/development/lib/dom/ssr/data.js +29 -0
  24. package/dist/development/lib/dom/ssr/entry.d.ts +59 -0
  25. package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  26. package/dist/development/lib/dom/ssr/errorBoundaries.js +83 -0
  27. package/dist/development/lib/dom/ssr/errors.d.ts +7 -0
  28. package/dist/development/lib/dom/ssr/errors.js +36 -0
  29. package/dist/development/lib/dom/ssr/fallback.js +28 -0
  30. package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
  31. package/dist/development/lib/dom/ssr/fog-of-war.js +170 -0
  32. package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
  33. package/dist/development/lib/dom/ssr/hydration.js +29 -0
  34. package/dist/development/lib/dom/ssr/invariant.js +16 -0
  35. package/dist/development/lib/dom/ssr/links.js +170 -0
  36. package/dist/development/lib/dom/ssr/markup.js +24 -0
  37. package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
  38. package/dist/development/lib/dom/ssr/routeModules.js +31 -0
  39. package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +62 -0
  40. package/dist/development/lib/dom/ssr/routes-test-stub.js +108 -0
  41. package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
  42. package/dist/development/lib/dom/ssr/routes.js +303 -0
  43. package/dist/development/lib/dom/ssr/server.d.ts +45 -0
  44. package/dist/development/lib/dom/ssr/server.js +68 -0
  45. package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
  46. package/dist/development/lib/dom/ssr/single-fetch.js +346 -0
  47. package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
  48. package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
  49. package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
  50. package/dist/development/lib/dom-export/hydrated-router.js +153 -0
  51. package/dist/development/lib/errors.js +29 -0
  52. package/dist/development/lib/hooks.d.ts +947 -0
  53. package/dist/development/lib/hooks.js +1386 -0
  54. package/dist/development/lib/href.d.ts +20 -0
  55. package/dist/development/lib/href.js +50 -0
  56. package/dist/development/lib/router/history.d.ts +258 -0
  57. package/dist/development/lib/router/history.js +371 -0
  58. package/dist/development/lib/router/instrumentation.d.ts +86 -0
  59. package/dist/development/lib/router/instrumentation.js +213 -0
  60. package/dist/development/lib/router/links.d.ts +113 -0
  61. package/dist/development/lib/router/router.d.ts +663 -0
  62. package/dist/development/lib/router/router.js +2981 -0
  63. package/dist/development/lib/router/utils.d.ts +942 -0
  64. package/dist/development/lib/router/utils.js +791 -0
  65. package/dist/development/lib/rsc/browser.d.ts +137 -0
  66. package/dist/development/lib/rsc/browser.js +599 -0
  67. package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
  68. package/dist/development/lib/rsc/errorBoundaries.js +90 -0
  69. package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
  70. package/dist/development/lib/rsc/html-stream/browser.js +74 -0
  71. package/dist/development/lib/rsc/html-stream/server.js +78 -0
  72. package/dist/development/lib/rsc/route-modules.js +27 -0
  73. package/dist/development/lib/rsc/server.rsc.d.ts +219 -0
  74. package/dist/development/lib/rsc/server.ssr.d.ts +129 -0
  75. package/dist/development/lib/rsc/server.ssr.js +388 -0
  76. package/dist/development/lib/server-runtime/build.d.ts +66 -0
  77. package/dist/development/lib/server-runtime/cookies.d.ts +66 -0
  78. package/dist/development/lib/server-runtime/cookies.js +139 -0
  79. package/dist/development/lib/server-runtime/crypto.js +43 -0
  80. package/dist/development/lib/server-runtime/data.d.ts +13 -0
  81. package/dist/development/lib/server-runtime/data.js +25 -0
  82. package/dist/development/lib/server-runtime/dev.d.ts +9 -0
  83. package/dist/development/lib/server-runtime/dev.js +26 -0
  84. package/dist/development/lib/server-runtime/entry.js +20 -0
  85. package/dist/development/lib/server-runtime/errors.js +95 -0
  86. package/dist/development/lib/server-runtime/headers.js +73 -0
  87. package/dist/development/lib/server-runtime/invariant.js +19 -0
  88. package/dist/development/lib/server-runtime/mode.d.ts +12 -0
  89. package/dist/development/lib/server-runtime/mode.js +25 -0
  90. package/dist/development/lib/server-runtime/routeMatching.js +28 -0
  91. package/dist/development/lib/server-runtime/routes.d.ts +13 -0
  92. package/dist/development/lib/server-runtime/routes.js +74 -0
  93. package/dist/development/lib/server-runtime/server.d.ts +10 -0
  94. package/dist/development/lib/server-runtime/server.js +351 -0
  95. package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
  96. package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
  97. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +45 -0
  98. package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
  99. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +52 -0
  100. package/dist/development/lib/server-runtime/sessions.d.ts +145 -0
  101. package/dist/development/lib/server-runtime/sessions.js +98 -0
  102. package/dist/development/lib/server-runtime/single-fetch.d.ts +7 -0
  103. package/dist/development/lib/server-runtime/single-fetch.js +215 -0
  104. package/dist/development/lib/server-runtime/urls.js +31 -0
  105. package/dist/development/lib/server-runtime/warnings.js +20 -0
  106. package/dist/development/lib/types/future.d.ts +9 -0
  107. package/dist/development/lib/types/internal.d.ts +26 -177
  108. package/dist/development/lib/types/internal.js +3 -2
  109. package/dist/{production/register-Bsscfj79.d.ts → development/lib/types/register.d.ts} +9 -15
  110. package/dist/development/lib/types/route-data.d.ts +113 -0
  111. package/dist/development/lib/types/route-module-annotations.d.ts +149 -0
  112. package/dist/development/lib/types/route-module.d.ts +19 -0
  113. package/dist/development/lib/types/serializes-to.d.ts +13 -0
  114. package/dist/development/lib/types/utils.d.ts +11 -0
  115. package/dist/development/vendor/turbo-stream-v2/flatten.js +159 -0
  116. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +178 -0
  117. package/dist/development/vendor/turbo-stream-v2/unflatten.js +198 -0
  118. package/dist/development/vendor/turbo-stream-v2/utils.js +47 -0
  119. package/dist/production/dom-export.d.ts +6 -172
  120. package/dist/production/dom-export.js +12 -1007
  121. package/dist/production/index-react-server-client.d.ts +7 -4
  122. package/dist/production/index-react-server-client.js +8 -52
  123. package/dist/production/index-react-server.d.ts +1645 -1635
  124. package/dist/production/index-react-server.js +2871 -3642
  125. package/dist/production/index.d.ts +43 -1469
  126. package/dist/production/index.js +37 -2621
  127. package/dist/production/lib/actions.js +62 -0
  128. package/dist/production/lib/components.d.ts +1022 -0
  129. package/dist/production/lib/components.js +835 -0
  130. package/dist/production/lib/context.d.ts +83 -0
  131. package/dist/production/lib/context.js +41 -0
  132. package/dist/production/lib/dom/dom.d.ts +119 -0
  133. package/dist/production/lib/dom/dom.js +143 -0
  134. package/dist/production/lib/dom/lib.d.ts +2042 -0
  135. package/dist/production/lib/dom/lib.js +1259 -0
  136. package/dist/production/lib/dom/server.d.ts +138 -0
  137. package/dist/production/lib/dom/server.js +301 -0
  138. package/dist/production/lib/dom/ssr/components.d.ts +196 -0
  139. package/dist/production/lib/dom/ssr/components.js +579 -0
  140. package/dist/production/lib/dom/ssr/data.js +29 -0
  141. package/dist/production/lib/dom/ssr/entry.d.ts +59 -0
  142. package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  143. package/dist/production/lib/dom/ssr/errorBoundaries.js +83 -0
  144. package/dist/production/lib/dom/ssr/errors.d.ts +7 -0
  145. package/dist/production/lib/dom/ssr/errors.js +36 -0
  146. package/dist/production/lib/dom/ssr/fallback.js +21 -0
  147. package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
  148. package/dist/production/lib/dom/ssr/fog-of-war.js +170 -0
  149. package/dist/production/lib/dom/ssr/hydration.d.ts +32 -0
  150. package/dist/production/lib/dom/ssr/hydration.js +29 -0
  151. package/dist/production/lib/dom/ssr/invariant.js +16 -0
  152. package/dist/production/lib/dom/ssr/links.js +170 -0
  153. package/dist/production/lib/dom/ssr/markup.js +24 -0
  154. package/dist/production/lib/dom/ssr/routeModules.d.ts +206 -0
  155. package/dist/production/lib/dom/ssr/routeModules.js +31 -0
  156. package/dist/production/lib/dom/ssr/routes-test-stub.d.ts +62 -0
  157. package/dist/production/lib/dom/ssr/routes-test-stub.js +108 -0
  158. package/dist/production/lib/dom/ssr/routes.d.ts +33 -0
  159. package/dist/production/lib/dom/ssr/routes.js +303 -0
  160. package/dist/production/lib/dom/ssr/server.d.ts +45 -0
  161. package/dist/production/lib/dom/ssr/server.js +68 -0
  162. package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
  163. package/dist/production/lib/dom/ssr/single-fetch.js +346 -0
  164. package/dist/production/lib/dom-export/dom-router-provider.d.ts +9 -0
  165. package/dist/production/lib/dom-export/dom-router-provider.js +22 -0
  166. package/dist/production/lib/dom-export/hydrated-router.d.ts +125 -0
  167. package/dist/production/lib/dom-export/hydrated-router.js +153 -0
  168. package/dist/production/lib/errors.js +29 -0
  169. package/dist/production/lib/hooks.d.ts +947 -0
  170. package/dist/production/lib/hooks.js +1371 -0
  171. package/dist/production/lib/href.d.ts +20 -0
  172. package/dist/production/lib/href.js +50 -0
  173. package/dist/production/lib/router/history.d.ts +258 -0
  174. package/dist/production/lib/router/history.js +371 -0
  175. package/dist/production/lib/router/instrumentation.d.ts +86 -0
  176. package/dist/production/lib/router/instrumentation.js +213 -0
  177. package/dist/production/lib/router/links.d.ts +113 -0
  178. package/dist/production/lib/router/router.d.ts +663 -0
  179. package/dist/production/lib/router/router.js +2981 -0
  180. package/dist/production/lib/router/utils.d.ts +942 -0
  181. package/dist/production/lib/router/utils.js +782 -0
  182. package/dist/production/lib/rsc/browser.d.ts +137 -0
  183. package/dist/production/lib/rsc/browser.js +599 -0
  184. package/dist/production/lib/rsc/errorBoundaries.d.ts +11 -0
  185. package/dist/production/lib/rsc/errorBoundaries.js +90 -0
  186. package/dist/production/lib/rsc/html-stream/browser.d.ts +48 -0
  187. package/dist/production/lib/rsc/html-stream/browser.js +74 -0
  188. package/dist/production/lib/rsc/html-stream/server.js +78 -0
  189. package/dist/production/lib/rsc/route-modules.js +27 -0
  190. package/dist/production/lib/rsc/server.rsc.d.ts +219 -0
  191. package/dist/production/lib/rsc/server.ssr.d.ts +129 -0
  192. package/dist/production/lib/rsc/server.ssr.js +388 -0
  193. package/dist/production/lib/server-runtime/build.d.ts +66 -0
  194. package/dist/production/lib/server-runtime/cookies.d.ts +66 -0
  195. package/dist/production/lib/server-runtime/cookies.js +139 -0
  196. package/dist/production/lib/server-runtime/crypto.js +43 -0
  197. package/dist/production/lib/server-runtime/data.d.ts +13 -0
  198. package/dist/production/lib/server-runtime/data.js +25 -0
  199. package/dist/production/lib/server-runtime/dev.d.ts +9 -0
  200. package/dist/production/lib/server-runtime/dev.js +26 -0
  201. package/dist/production/lib/server-runtime/entry.js +20 -0
  202. package/dist/production/lib/server-runtime/errors.js +95 -0
  203. package/dist/production/lib/server-runtime/headers.js +73 -0
  204. package/dist/production/lib/server-runtime/invariant.js +19 -0
  205. package/dist/production/lib/server-runtime/mode.d.ts +12 -0
  206. package/dist/production/lib/server-runtime/mode.js +25 -0
  207. package/dist/production/lib/server-runtime/routeMatching.js +28 -0
  208. package/dist/production/lib/server-runtime/routes.d.ts +13 -0
  209. package/dist/production/lib/server-runtime/routes.js +74 -0
  210. package/dist/production/lib/server-runtime/server.d.ts +10 -0
  211. package/dist/production/lib/server-runtime/server.js +351 -0
  212. package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
  213. package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
  214. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +45 -0
  215. package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
  216. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +52 -0
  217. package/dist/production/lib/server-runtime/sessions.d.ts +145 -0
  218. package/dist/production/lib/server-runtime/sessions.js +98 -0
  219. package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
  220. package/dist/production/lib/server-runtime/single-fetch.js +215 -0
  221. package/dist/production/lib/server-runtime/urls.js +31 -0
  222. package/dist/production/lib/server-runtime/warnings.js +20 -0
  223. package/dist/production/lib/types/future.d.ts +9 -0
  224. package/dist/production/lib/types/internal.d.ts +26 -177
  225. package/dist/production/lib/types/internal.js +3 -2
  226. package/dist/{development/register-Bsscfj79.d.ts → production/lib/types/register.d.ts} +9 -15
  227. package/dist/production/lib/types/route-data.d.ts +113 -0
  228. package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
  229. package/dist/production/lib/types/route-module.d.ts +19 -0
  230. package/dist/production/lib/types/serializes-to.d.ts +13 -0
  231. package/dist/production/lib/types/utils.d.ts +11 -0
  232. package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
  233. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +178 -0
  234. package/dist/production/vendor/turbo-stream-v2/unflatten.js +198 -0
  235. package/dist/production/vendor/turbo-stream-v2/utils.js +47 -0
  236. package/docs/explanation/backend-for-frontend.md +50 -0
  237. package/docs/explanation/code-splitting.md +77 -0
  238. package/docs/explanation/concurrency.md +135 -0
  239. package/docs/explanation/form-vs-fetcher.md +292 -0
  240. package/docs/explanation/hot-module-replacement.md +137 -0
  241. package/docs/explanation/hydration.md +14 -0
  242. package/docs/explanation/index-query-param.md +86 -0
  243. package/docs/explanation/index.md +4 -0
  244. package/docs/explanation/lazy-route-discovery.md +78 -0
  245. package/docs/explanation/location.md +6 -0
  246. package/docs/explanation/progressive-enhancement.md +150 -0
  247. package/docs/explanation/race-conditions.md +88 -0
  248. package/docs/explanation/react-transitions.md +160 -0
  249. package/docs/explanation/route-matching.md +7 -0
  250. package/docs/explanation/server-client-execution.md +4 -0
  251. package/docs/explanation/sessions-and-cookies.md +465 -0
  252. package/docs/explanation/special-files.md +16 -0
  253. package/docs/explanation/state-management.md +524 -0
  254. package/docs/explanation/styling.md +87 -0
  255. package/docs/explanation/type-safety.md +82 -0
  256. package/docs/how-to/accessibility.md +44 -0
  257. package/docs/how-to/client-data.md +199 -0
  258. package/docs/how-to/data-strategy.md +317 -0
  259. package/docs/how-to/error-boundary.md +231 -0
  260. package/docs/how-to/error-reporting.md +134 -0
  261. package/docs/how-to/fetchers.md +307 -0
  262. package/docs/how-to/file-route-conventions.md +410 -0
  263. package/docs/how-to/file-uploads.md +217 -0
  264. package/docs/how-to/form-validation.md +120 -0
  265. package/docs/how-to/headers.md +164 -0
  266. package/docs/how-to/index.md +4 -0
  267. package/docs/how-to/instrumentation.md +556 -0
  268. package/docs/how-to/meta.md +40 -0
  269. package/docs/how-to/middleware.md +728 -0
  270. package/docs/how-to/navigation-blocking.md +233 -0
  271. package/docs/how-to/optimize-revalidation.md +12 -0
  272. package/docs/how-to/pre-rendering.md +225 -0
  273. package/docs/how-to/presets.md +103 -0
  274. package/docs/how-to/react-server-components.md +899 -0
  275. package/docs/how-to/resource-routes.md +126 -0
  276. package/docs/how-to/route-module-type-safety.md +100 -0
  277. package/docs/how-to/search-params.md +4 -0
  278. package/docs/how-to/security.md +30 -0
  279. package/docs/how-to/server-bundles.md +66 -0
  280. package/docs/how-to/spa.md +120 -0
  281. package/docs/how-to/status.md +63 -0
  282. package/docs/how-to/suspense.md +132 -0
  283. package/docs/how-to/using-handle.md +117 -0
  284. package/docs/how-to/view-transitions.md +237 -0
  285. package/docs/how-to/webhook.md +50 -0
  286. package/docs/index.md +39 -0
  287. package/docs/start/data/actions.md +138 -0
  288. package/docs/start/data/custom.md +198 -0
  289. package/docs/start/data/data-loading.md +44 -0
  290. package/docs/start/data/index.md +4 -0
  291. package/docs/start/data/installation.md +52 -0
  292. package/docs/start/data/navigating.md +12 -0
  293. package/docs/start/data/pending-ui.md +12 -0
  294. package/docs/start/data/route-object.md +248 -0
  295. package/docs/start/data/routing.md +281 -0
  296. package/docs/start/data/testing.md +8 -0
  297. package/docs/start/declarative/index.md +4 -0
  298. package/docs/start/declarative/installation.md +43 -0
  299. package/docs/start/declarative/navigating.md +133 -0
  300. package/docs/start/declarative/routing.md +237 -0
  301. package/docs/start/declarative/url-values.md +65 -0
  302. package/docs/start/framework/actions.md +175 -0
  303. package/docs/start/framework/data-loading.md +201 -0
  304. package/docs/start/framework/deploying.md +96 -0
  305. package/docs/start/framework/index.md +4 -0
  306. package/docs/start/framework/installation.md +42 -0
  307. package/docs/start/framework/navigating.md +182 -0
  308. package/docs/start/framework/pending-ui.md +142 -0
  309. package/docs/start/framework/rendering.md +59 -0
  310. package/docs/start/framework/route-module.md +527 -0
  311. package/docs/start/framework/routing.md +362 -0
  312. package/docs/start/framework/testing.md +133 -0
  313. package/docs/start/index.md +4 -0
  314. package/docs/start/modes.md +201 -0
  315. package/docs/upgrading/component-routes.md +363 -0
  316. package/docs/upgrading/future.md +31 -0
  317. package/docs/upgrading/index.md +4 -0
  318. package/docs/upgrading/remix.md +403 -0
  319. package/docs/upgrading/router-provider.md +442 -0
  320. package/docs/upgrading/v6.md +379 -0
  321. package/package.json +44 -87
  322. package/dist/development/browser-3AnU12UI.d.mts +0 -318
  323. package/dist/development/browser-BOdXz9dK.d.ts +0 -318
  324. package/dist/development/chunk-4N6VE7H7.mjs +0 -11528
  325. package/dist/development/chunk-4YRVXM2U.js +0 -188
  326. package/dist/development/chunk-66UKHEGQ.js +0 -1362
  327. package/dist/development/chunk-D6LUOGOQ.js +0 -10229
  328. package/dist/development/chunk-RJYABSBD.mjs +0 -2585
  329. package/dist/development/context-ByvtofY2.d.mts +0 -1771
  330. package/dist/development/data-BVUf681J.d.mts +0 -1732
  331. package/dist/development/data-BqZ2x964.d.ts +0 -1732
  332. package/dist/development/dom-export.d.mts +0 -172
  333. package/dist/development/dom-export.mjs +0 -1008
  334. package/dist/development/index-react-server-client-BS5F89FR.d.ts +0 -3655
  335. package/dist/development/index-react-server-client-DY04-103.d.mts +0 -2600
  336. package/dist/development/index-react-server-client.d.mts +0 -4
  337. package/dist/development/index-react-server-client.mjs +0 -59
  338. package/dist/development/index-react-server.d.mts +0 -2703
  339. package/dist/development/index-react-server.mjs +0 -3780
  340. package/dist/development/index.d.mts +0 -1472
  341. package/dist/development/index.mjs +0 -277
  342. package/dist/development/instrumentation-cRWWLfsU.d.ts +0 -715
  343. package/dist/development/lib/types/internal.d.mts +0 -184
  344. package/dist/development/lib/types/internal.mjs +0 -10
  345. package/dist/development/register-Df8okEea.d.mts +0 -30
  346. package/dist/production/browser-3AnU12UI.d.mts +0 -318
  347. package/dist/production/browser-BOdXz9dK.d.ts +0 -318
  348. package/dist/production/chunk-6S4627ZB.mjs +0 -2585
  349. package/dist/production/chunk-HUBUW7R3.js +0 -10229
  350. package/dist/production/chunk-JAKZPQZC.mjs +0 -11528
  351. package/dist/production/chunk-PNZCCTKT.js +0 -1362
  352. package/dist/production/chunk-Y6IFXO7V.js +0 -188
  353. package/dist/production/context-ByvtofY2.d.mts +0 -1771
  354. package/dist/production/data-BVUf681J.d.mts +0 -1732
  355. package/dist/production/data-BqZ2x964.d.ts +0 -1732
  356. package/dist/production/dom-export.d.mts +0 -172
  357. package/dist/production/dom-export.mjs +0 -1008
  358. package/dist/production/index-react-server-client-BS5F89FR.d.ts +0 -3655
  359. package/dist/production/index-react-server-client-DY04-103.d.mts +0 -2600
  360. package/dist/production/index-react-server-client.d.mts +0 -4
  361. package/dist/production/index-react-server-client.mjs +0 -59
  362. package/dist/production/index-react-server.d.mts +0 -2703
  363. package/dist/production/index-react-server.mjs +0 -3780
  364. package/dist/production/index.d.mts +0 -1472
  365. package/dist/production/index.mjs +0 -277
  366. package/dist/production/instrumentation-cRWWLfsU.d.ts +0 -715
  367. package/dist/production/lib/types/internal.d.mts +0 -184
  368. package/dist/production/lib/types/internal.mjs +0 -10
  369. package/dist/production/register-Df8okEea.d.mts +0 -30
@@ -1,2703 +0,0 @@
1
- import * as React from 'react';
2
- export { BrowserRouter, Form, HashRouter, Link, Links, MemoryRouter, Meta, NavLink, Navigate, Outlet, Route, Router, RouterProvider, Routes, ScrollRestoration, StaticRouter, StaticRouterProvider, unstable_HistoryRouter } from 'react-router/internal/react-server-client';
3
- import { ParseOptions, SerializeOptions } from 'cookie';
4
- export { ParseOptions as CookieParseOptions, SerializeOptions as CookieSerializeOptions } from 'cookie';
5
-
6
- /**
7
- * Actions represent the type of change to a location value.
8
- */
9
- declare enum Action {
10
- /**
11
- * A POP indicates a change to an arbitrary index in the history stack, such
12
- * as a back or forward navigation. It does not describe the direction of the
13
- * navigation, only that the current index changed.
14
- *
15
- * Note: This is the default action for newly created history objects.
16
- */
17
- Pop = "POP",
18
- /**
19
- * A PUSH indicates a new entry being added to the history stack, such as when
20
- * a link is clicked and a new page loads. When this happens, all subsequent
21
- * entries in the stack are lost.
22
- */
23
- Push = "PUSH",
24
- /**
25
- * A REPLACE indicates the entry at the current index in the history stack
26
- * being replaced by a new one.
27
- */
28
- Replace = "REPLACE"
29
- }
30
- /**
31
- * The pathname, search, and hash values of a URL.
32
- */
33
- interface Path {
34
- /**
35
- * A URL pathname, beginning with a /.
36
- */
37
- pathname: string;
38
- /**
39
- * A URL search string, beginning with a ?.
40
- */
41
- search: string;
42
- /**
43
- * A URL fragment identifier, beginning with a #.
44
- */
45
- hash: string;
46
- }
47
- /**
48
- * An entry in a history stack. A location contains information about the
49
- * URL path, as well as possibly some arbitrary state and a key.
50
- */
51
- interface Location<State = any> extends Path {
52
- /**
53
- * A value of arbitrary data associated with this location.
54
- */
55
- state: State;
56
- /**
57
- * A unique string associated with this location. May be used to safely store
58
- * and retrieve data in some other storage API, like `localStorage`.
59
- *
60
- * Note: This value is always "default" on the initial location.
61
- */
62
- key: string;
63
- /**
64
- * The masked location displayed in the URL bar, which differs from the URL the
65
- * router is operating on
66
- */
67
- mask?: Path;
68
- }
69
- /**
70
- * A change to the current location.
71
- */
72
- interface Update {
73
- /**
74
- * The action that triggered the change.
75
- */
76
- action: Action;
77
- /**
78
- * The new location.
79
- */
80
- location: Location;
81
- /**
82
- * The delta between this location and the former location in the history stack
83
- */
84
- delta: number | null;
85
- }
86
- /**
87
- * A function that receives notifications about location changes.
88
- */
89
- interface Listener {
90
- (update: Update): void;
91
- }
92
- /**
93
- * Describes a location that is the destination of some navigation used in
94
- * {@link Link}, {@link useNavigate}, etc.
95
- */
96
- type To = string | Partial<Path>;
97
- /**
98
- * A history is an interface to the navigation stack. The history serves as the
99
- * source of truth for the current location, as well as provides a set of
100
- * methods that may be used to change it.
101
- *
102
- * It is similar to the DOM's `window.history` object, but with a smaller, more
103
- * focused API.
104
- */
105
- interface History {
106
- /**
107
- * The last action that modified the current location. This will always be
108
- * Action.Pop when a history instance is first created. This value is mutable.
109
- */
110
- readonly action: Action;
111
- /**
112
- * The current location. This value is mutable.
113
- */
114
- readonly location: Location;
115
- /**
116
- * Returns a valid href for the given `to` value that may be used as
117
- * the value of an <a href> attribute.
118
- *
119
- * @param to - The destination URL
120
- */
121
- createHref(to: To): string;
122
- /**
123
- * Returns a URL for the given `to` value
124
- *
125
- * @param to - The destination URL
126
- */
127
- createURL(to: To): URL;
128
- /**
129
- * Encode a location the same way window.history would do (no-op for memory
130
- * history) so we ensure our PUSH/REPLACE navigations for data routers
131
- * behave the same as POP
132
- *
133
- * @param to Unencoded path
134
- */
135
- encodeLocation(to: To): Path;
136
- /**
137
- * Pushes a new location onto the history stack, increasing its length by one.
138
- * If there were any entries in the stack after the current one, they are
139
- * lost.
140
- *
141
- * @param to - The new URL
142
- * @param state - Data to associate with the new location
143
- */
144
- push(to: To, state?: any): void;
145
- /**
146
- * Replaces the current location in the history stack with a new one. The
147
- * location that was replaced will no longer be available.
148
- *
149
- * @param to - The new URL
150
- * @param state - Data to associate with the new location
151
- */
152
- replace(to: To, state?: any): void;
153
- /**
154
- * Navigates `n` entries backward/forward in the history stack relative to the
155
- * current index. For example, a "back" navigation would use go(-1).
156
- *
157
- * @param delta - The delta in the stack index
158
- */
159
- go(delta: number): void;
160
- /**
161
- * Sets up a listener that will be called whenever the current location
162
- * changes.
163
- *
164
- * @param listener - A function that will be called when the location changes
165
- * @returns unlisten - A function that may be used to stop listening
166
- */
167
- listen(listener: Listener): () => void;
168
- }
169
-
170
- /**
171
- * An augmentable interface users can modify in their app-code to opt into
172
- * future-flag-specific types
173
- */
174
- interface Future {
175
- }
176
- type MiddlewareEnabled = Future extends {
177
- v8_middleware: infer T extends boolean;
178
- } ? T : false;
179
-
180
- type MaybePromise<T> = T | Promise<T>;
181
- /**
182
- * Map of routeId -> data returned from a loader/action/error
183
- */
184
- interface RouteData {
185
- [routeId: string]: any;
186
- }
187
- type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
188
- type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
189
- /**
190
- * Users can specify either lowercase or uppercase form methods on `<Form>`,
191
- * useSubmit(), `<fetcher.Form>`, etc.
192
- */
193
- type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
194
- /**
195
- * Active navigation/fetcher form methods are exposed in uppercase on the
196
- * RouterState. This is to align with the normalization done via fetch().
197
- */
198
- type FormMethod = UpperCaseFormMethod;
199
- type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
200
- type JsonObject = {
201
- [Key in string]: JsonValue;
202
- } & {
203
- [Key in string]?: JsonValue | undefined;
204
- };
205
- type JsonArray = JsonValue[] | readonly JsonValue[];
206
- type JsonPrimitive = string | number | boolean | null;
207
- type JsonValue = JsonPrimitive | JsonObject | JsonArray;
208
- /**
209
- * @private
210
- * Internal interface to pass around for action submissions, not intended for
211
- * external consumption
212
- */
213
- type Submission = {
214
- formMethod: FormMethod;
215
- formAction: string;
216
- formEncType: FormEncType;
217
- formData: FormData;
218
- json: undefined;
219
- text: undefined;
220
- } | {
221
- formMethod: FormMethod;
222
- formAction: string;
223
- formEncType: FormEncType;
224
- formData: undefined;
225
- json: JsonValue;
226
- text: undefined;
227
- } | {
228
- formMethod: FormMethod;
229
- formAction: string;
230
- formEncType: FormEncType;
231
- formData: undefined;
232
- json: undefined;
233
- text: string;
234
- };
235
- /**
236
- * A context instance used as the key for the `get`/`set` methods of a
237
- * {@link RouterContextProvider}. Accepts an optional default
238
- * value to be returned if no value has been set.
239
- */
240
- interface RouterContext<T = unknown> {
241
- defaultValue?: T;
242
- }
243
- /**
244
- * Creates a type-safe {@link RouterContext} object that can be used to
245
- * store and retrieve arbitrary values in [`action`](../../start/framework/route-module#action)s,
246
- * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
247
- * Similar to React's [`createContext`](https://react.dev/reference/react/createContext),
248
- * but specifically designed for React Router's request/response lifecycle.
249
- *
250
- * If a `defaultValue` is provided, it will be returned from `context.get()`
251
- * when no value has been set for the context. Otherwise, reading this context
252
- * when no value has been set will throw an error.
253
- *
254
- * ```tsx filename=app/context.ts
255
- * import { createContext } from "react-router";
256
- *
257
- * // Create a context for user data
258
- * export const userContext =
259
- * createContext<User | null>(null);
260
- * ```
261
- *
262
- * ```tsx filename=app/middleware/auth.ts
263
- * import { getUserFromSession } from "~/auth.server";
264
- * import { userContext } from "~/context";
265
- *
266
- * export const authMiddleware = async ({
267
- * context,
268
- * request,
269
- * }) => {
270
- * const user = await getUserFromSession(request);
271
- * context.set(userContext, user);
272
- * };
273
- * ```
274
- *
275
- * ```tsx filename=app/routes/profile.tsx
276
- * import { userContext } from "~/context";
277
- *
278
- * export async function loader({
279
- * context,
280
- * }: Route.LoaderArgs) {
281
- * const user = context.get(userContext);
282
- *
283
- * if (!user) {
284
- * throw new Response("Unauthorized", { status: 401 });
285
- * }
286
- *
287
- * return { user };
288
- * }
289
- * ```
290
- *
291
- * @public
292
- * @category Utils
293
- * @mode framework
294
- * @mode data
295
- * @param defaultValue An optional default value for the context. This value
296
- * will be returned if no value has been set for this context.
297
- * @returns A {@link RouterContext} object that can be used with
298
- * `context.get()` and `context.set()` in [`action`](../../start/framework/route-module#action)s,
299
- * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
300
- */
301
- declare function createContext<T>(defaultValue?: T): RouterContext<T>;
302
- /**
303
- * Provides methods for writing/reading values in application context in a
304
- * type-safe way. Primarily for usage with [middleware](../../how-to/middleware).
305
- *
306
- * @example
307
- * import {
308
- * createContext,
309
- * RouterContextProvider
310
- * } from "react-router";
311
- *
312
- * const userContext = createContext<User | null>(null);
313
- * const contextProvider = new RouterContextProvider();
314
- * contextProvider.set(userContext, getUser());
315
- * // ^ Type-safe
316
- * const user = contextProvider.get(userContext);
317
- * // ^ User
318
- *
319
- * @public
320
- * @category Utils
321
- * @mode framework
322
- * @mode data
323
- */
324
- declare class RouterContextProvider {
325
- #private;
326
- /**
327
- * Create a new `RouterContextProvider` instance
328
- * @param init An optional initial context map to populate the provider with
329
- */
330
- constructor(init?: Map<RouterContext, unknown>);
331
- /**
332
- * Access a value from the context. If no value has been set for the context,
333
- * it will return the context's `defaultValue` if provided, or throw an error
334
- * if no `defaultValue` was set.
335
- * @param context The context to get the value for
336
- * @returns The value for the context, or the context's `defaultValue` if no
337
- * value was set
338
- */
339
- get<T>(context: RouterContext<T>): T;
340
- /**
341
- * Set a value for the context. If the context already has a value set, this
342
- * will overwrite it.
343
- *
344
- * @param context The context to set the value for
345
- * @param value The value to set for the context
346
- * @returns {void}
347
- */
348
- set<C extends RouterContext>(context: C, value: C extends RouterContext<infer T> ? T : never): void;
349
- }
350
- type DefaultContext = MiddlewareEnabled extends true ? Readonly<RouterContextProvider> : any;
351
- /**
352
- * @private
353
- * Arguments passed to route loader/action functions. Same for now but we keep
354
- * this as a private implementation detail in case they diverge in the future.
355
- */
356
- interface DataFunctionArgs<Context> {
357
- /** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read headers (like cookies, and {@link https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams URLSearchParams} from the request. */
358
- request: Request;
359
- /**
360
- * A URL instance representing the application location being navigated to or
361
- * fetched. By default, this matches `request.url`.
362
- *
363
- * In Framework mode with `future.v8_passThroughRequests` enabled, this is a
364
- * normalized URL with React-Router-specific implementation details removed
365
- * (`.data` suffixes, `index`/`_routes` search params).
366
- */
367
- url: URL;
368
- /**
369
- * Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
370
- * Mostly useful as a identifier to aggregate on for logging/tracing/etc.
371
- */
372
- pattern: string;
373
- /**
374
- * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
375
- * @example
376
- * // app/routes.ts
377
- * route("teams/:teamId", "./team.tsx"),
378
- *
379
- * // app/team.tsx
380
- * export function loader({
381
- * params,
382
- * }: Route.LoaderArgs) {
383
- * params.teamId;
384
- * // ^ string
385
- * }
386
- */
387
- params: Params;
388
- /**
389
- * This is the context passed in to your server adapter's getLoadContext() function.
390
- * It's a way to bridge the gap between the adapter's request/response API with your React Router app.
391
- * It is only applicable if you are using a custom server adapter.
392
- */
393
- context: Context;
394
- }
395
- /**
396
- * Route middleware `next` function to call downstream handlers and then complete
397
- * middlewares from the bottom-up
398
- */
399
- interface MiddlewareNextFunction<Result = unknown> {
400
- (): Promise<Result>;
401
- }
402
- /**
403
- * Route middleware function signature. Receives the same "data" arguments as a
404
- * `loader`/`action` (`request`, `params`, `context`) as the first parameter and
405
- * a `next` function as the second parameter which will call downstream handlers
406
- * and then complete middlewares from the bottom-up
407
- */
408
- type MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<Readonly<RouterContextProvider>>, next: MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
409
- /**
410
- * Arguments passed to loader functions
411
- */
412
- interface LoaderFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
413
- }
414
- /**
415
- * Arguments passed to action functions
416
- */
417
- interface ActionFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
418
- }
419
- /**
420
- * Loaders and actions can return anything
421
- */
422
- type DataFunctionValue = unknown;
423
- type DataFunctionReturnValue = MaybePromise<DataFunctionValue>;
424
- /**
425
- * Route loader function signature
426
- */
427
- type LoaderFunction<Context = DefaultContext> = {
428
- (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
429
- } & {
430
- hydrate?: boolean;
431
- };
432
- /**
433
- * Route action function signature
434
- */
435
- interface ActionFunction<Context = DefaultContext> {
436
- (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
437
- }
438
- /**
439
- * Arguments passed to shouldRevalidate function
440
- */
441
- interface ShouldRevalidateFunctionArgs {
442
- /** This is the url the navigation started from. You can compare it with `nextUrl` to decide if you need to revalidate this route's data. */
443
- currentUrl: URL;
444
- /** These are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the URL that can be compared to the `nextParams` to decide if you need to reload or not. Perhaps you're using only a partial piece of the param for data loading, you don't need to revalidate if a superfluous part of the param changed. */
445
- currentParams: DataRouteMatch["params"];
446
- /** In the case of navigation, this the URL the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentUrl. */
447
- nextUrl: URL;
448
- /** In the case of navigation, these are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the next location the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentParams. */
449
- nextParams: DataRouteMatch["params"];
450
- /** The method (probably `"GET"` or `"POST"`) used in the form submission that triggered the revalidation. */
451
- formMethod?: Submission["formMethod"];
452
- /** The form action (`<Form action="/somewhere">`) that triggered the revalidation. */
453
- formAction?: Submission["formAction"];
454
- /** The form encType (`<Form encType="application/x-www-form-urlencoded">) used in the form submission that triggered the revalidation*/
455
- formEncType?: Submission["formEncType"];
456
- /** The form submission data when the form's encType is `text/plain` */
457
- text?: Submission["text"];
458
- /** The form submission data when the form's encType is `application/x-www-form-urlencoded` or `multipart/form-data` */
459
- formData?: Submission["formData"];
460
- /** The form submission data when the form's encType is `application/json` */
461
- json?: Submission["json"];
462
- /** The status code of the action response */
463
- actionStatus?: number;
464
- /**
465
- * When a submission causes the revalidation this will be the result of the action—either action data or an error if the action failed. It's common to include some information in the action result to instruct shouldRevalidate to revalidate or not.
466
- *
467
- * @example
468
- * export async function action() {
469
- * await saveSomeStuff();
470
- * return { ok: true };
471
- * }
472
- *
473
- * export function shouldRevalidate({
474
- * actionResult,
475
- * }) {
476
- * if (actionResult?.ok) {
477
- * return false;
478
- * }
479
- * return true;
480
- * }
481
- */
482
- actionResult?: any;
483
- /**
484
- * By default, React Router doesn't call every loader all the time. There are reliable optimizations it can make by default. For example, only loaders with changing params are called. Consider navigating from the following URL to the one below it:
485
- *
486
- * /projects/123/tasks/abc
487
- * /projects/123/tasks/def
488
- * React Router will only call the loader for tasks/def because the param for projects/123 didn't change.
489
- *
490
- * It's safest to always return defaultShouldRevalidate after you've done your specific optimizations that return false, otherwise your UI might get out of sync with your data on the server.
491
- */
492
- defaultShouldRevalidate: boolean;
493
- }
494
- /**
495
- * Route shouldRevalidate function signature. This runs after any submission
496
- * (navigation or fetcher), so we flatten the navigation/fetcher submission
497
- * onto the arguments. It shouldn't matter whether it came from a navigation
498
- * or a fetcher, what really matters is the URLs and the formData since loaders
499
- * have to re-run based on the data models that were potentially mutated.
500
- */
501
- interface ShouldRevalidateFunction {
502
- (args: ShouldRevalidateFunctionArgs): boolean;
503
- }
504
- interface DataStrategyMatch extends RouteMatch<string, DataRouteObject> {
505
- /**
506
- * @private
507
- */
508
- _lazyPromises?: {
509
- middleware: Promise<void> | undefined;
510
- handler: Promise<void> | undefined;
511
- route: Promise<void> | undefined;
512
- };
513
- /**
514
- * @deprecated Deprecated in favor of `shouldCallHandler`
515
- *
516
- * A boolean value indicating whether this route handler should be called in
517
- * this pass.
518
- *
519
- * The `matches` array always includes _all_ matched routes even when only
520
- * _some_ route handlers need to be called so that things like middleware can
521
- * be implemented.
522
- *
523
- * `shouldLoad` is usually only interesting if you are skipping the route
524
- * handler entirely and implementing custom handler logic - since it lets you
525
- * determine if that custom logic should run for this route or not.
526
- *
527
- * For example:
528
- * - If you are on `/parent/child/a` and you navigate to `/parent/child/b` -
529
- * you'll get an array of three matches (`[parent, child, b]`), but only `b`
530
- * will have `shouldLoad=true` because the data for `parent` and `child` is
531
- * already loaded
532
- * - If you are on `/parent/child/a` and you submit to `a`'s [`action`](https://reactrouter.com/docs/start/data/route-object#action),
533
- * then only `a` will have `shouldLoad=true` for the action execution of
534
- * `dataStrategy`
535
- * - After the [`action`](https://reactrouter.com/docs/start/data/route-object#action),
536
- * `dataStrategy` will be called again for the [`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
537
- * revalidation, and all matches will have `shouldLoad=true` (assuming no
538
- * custom `shouldRevalidate` implementations)
539
- */
540
- shouldLoad: boolean;
541
- /**
542
- * Arguments passed to the `shouldRevalidate` function for this `loader` execution.
543
- * Will be `null` if this is not a revalidating loader {@link DataStrategyMatch}.
544
- */
545
- shouldRevalidateArgs: ShouldRevalidateFunctionArgs | null;
546
- /**
547
- * Determine if this route's handler should be called during this `dataStrategy`
548
- * execution. Calling it with no arguments will leverage the default revalidation
549
- * behavior. You can pass your own `defaultShouldRevalidate` value if you wish
550
- * to change the default revalidation behavior with your `dataStrategy`.
551
- *
552
- * @param defaultShouldRevalidate `defaultShouldRevalidate` override value (optional)
553
- */
554
- shouldCallHandler(defaultShouldRevalidate?: boolean): boolean;
555
- /**
556
- * An async function that will resolve any `route.lazy` implementations and
557
- * execute the route's handler (if necessary), returning a {@link DataStrategyResult}
558
- *
559
- * - Calling `match.resolve` does not mean you're calling the
560
- * [`action`](https://reactrouter.com/docs/start/data/route-object#action)/[`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
561
- * (the "handler") - `resolve` will only call the `handler` internally if
562
- * needed _and_ if you don't pass your own `handlerOverride` function parameter
563
- * - It is safe to call `match.resolve` for all matches, even if they have
564
- * `shouldLoad=false`, and it will no-op if no loading is required
565
- * - You should generally always call `match.resolve()` for `shouldLoad:true`
566
- * routes to ensure that any `route.lazy` implementations are processed
567
- * - See the examples below for how to implement custom handler execution via
568
- * `match.resolve`
569
- */
570
- resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
571
- }
572
- interface DataStrategyFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
573
- /**
574
- * Matches for this route extended with Data strategy APIs
575
- */
576
- matches: DataStrategyMatch[];
577
- runClientMiddleware: (cb: DataStrategyFunction<Context>) => Promise<Record<string, DataStrategyResult>>;
578
- /**
579
- * The key of the fetcher we are calling `dataStrategy` for, otherwise `null`
580
- * for navigational executions
581
- */
582
- fetcherKey: string | null;
583
- }
584
- /**
585
- * Result from a loader or action called via dataStrategy
586
- */
587
- interface DataStrategyResult {
588
- type: "data" | "error";
589
- result: unknown;
590
- }
591
- interface DataStrategyFunction<Context = DefaultContext> {
592
- (args: DataStrategyFunctionArgs<Context>): Promise<Record<string, DataStrategyResult>>;
593
- }
594
- type PatchRoutesOnNavigationFunctionArgs = {
595
- signal: AbortSignal;
596
- path: string;
597
- matches: RouteMatch[];
598
- fetcherKey: string | undefined;
599
- patch: (routeId: string | null, children: RouteObject[]) => void;
600
- };
601
- type PatchRoutesOnNavigationFunction = (opts: PatchRoutesOnNavigationFunctionArgs) => MaybePromise<void>;
602
- /**
603
- * Function provided to set route-specific properties from route objects
604
- */
605
- interface MapRoutePropertiesFunction {
606
- (route: DataRouteObject): {
607
- hasErrorBoundary: boolean;
608
- } & Record<string, any>;
609
- }
610
- /**
611
- * Keys we cannot change from within a lazy object. We spread all other keys
612
- * onto the route. Either they're meaningful to the router, or they'll get
613
- * ignored.
614
- */
615
- type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
616
- /**
617
- * Keys we cannot change from within a lazy() function. We spread all other keys
618
- * onto the route. Either they're meaningful to the router, or they'll get
619
- * ignored.
620
- */
621
- type UnsupportedLazyRouteFunctionKey = UnsupportedLazyRouteObjectKey | "middleware";
622
- /**
623
- * lazy object to load route properties, which can add non-matching
624
- * related properties to a route
625
- */
626
- type LazyRouteObject<R extends RouteObject> = {
627
- [K in keyof R as K extends UnsupportedLazyRouteObjectKey ? never : K]?: () => Promise<R[K] | null | undefined>;
628
- };
629
- /**
630
- * lazy() function to load a route definition, which can add non-matching
631
- * related properties to a route
632
- */
633
- interface LazyRouteFunction<R extends RouteObject> {
634
- (): Promise<Omit<R, UnsupportedLazyRouteFunctionKey> & Partial<Record<UnsupportedLazyRouteFunctionKey, never>>>;
635
- }
636
- type LazyRouteDefinition<R extends RouteObject> = LazyRouteObject<R> | LazyRouteFunction<R>;
637
- /**
638
- * Base RouteObject with common props shared by all types of routes
639
- * @internal
640
- */
641
- type BaseRouteObject = {
642
- /**
643
- * Whether the path should be case-sensitive. Defaults to `false`.
644
- */
645
- caseSensitive?: boolean;
646
- /**
647
- * The path pattern to match. If unspecified or empty, then this becomes a
648
- * layout route.
649
- */
650
- path?: string;
651
- /**
652
- * The unique identifier for this route (for use with {@link DataRouter}s)
653
- */
654
- id?: string;
655
- /**
656
- * The route middleware.
657
- * See [`middleware`](../../start/data/route-object#middleware).
658
- */
659
- middleware?: MiddlewareFunction[];
660
- /**
661
- * The route loader.
662
- * See [`loader`](../../start/data/route-object#loader).
663
- */
664
- loader?: LoaderFunction | boolean;
665
- /**
666
- * The route action.
667
- * See [`action`](../../start/data/route-object#action).
668
- */
669
- action?: ActionFunction | boolean;
670
- hasErrorBoundary?: boolean;
671
- /**
672
- * The route shouldRevalidate function.
673
- * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
674
- */
675
- shouldRevalidate?: ShouldRevalidateFunction;
676
- /**
677
- * The route handle.
678
- */
679
- handle?: any;
680
- /**
681
- * A function that returns a promise that resolves to the route object.
682
- * Used for code-splitting routes.
683
- * See [`lazy`](../../start/data/route-object#lazy).
684
- */
685
- lazy?: LazyRouteDefinition<BaseRouteObject>;
686
- /**
687
- * The React Component to render when this route matches.
688
- * Mutually exclusive with `element`.
689
- */
690
- Component?: React.ComponentType | null;
691
- /**
692
- * The React element to render when this Route matches.
693
- * Mutually exclusive with `Component`.
694
- */
695
- element?: React.ReactNode | null;
696
- /**
697
- * The React Component to render at this route if an error occurs.
698
- * Mutually exclusive with `errorElement`.
699
- */
700
- ErrorBoundary?: React.ComponentType | null;
701
- /**
702
- * The React element to render at this route if an error occurs.
703
- * Mutually exclusive with `ErrorBoundary`.
704
- */
705
- errorElement?: React.ReactNode | null;
706
- /**
707
- * The React Component to render while this router is loading data.
708
- * Mutually exclusive with `hydrateFallbackElement`.
709
- */
710
- HydrateFallback?: React.ComponentType | null;
711
- /**
712
- * The React element to render while this router is loading data.
713
- * Mutually exclusive with `HydrateFallback`.
714
- */
715
- hydrateFallbackElement?: React.ReactNode | null;
716
- };
717
- /**
718
- * Index routes must not have children
719
- */
720
- type IndexRouteObject = BaseRouteObject & {
721
- /**
722
- * Child Route objects - not valid on index routes.
723
- */
724
- children?: undefined;
725
- /**
726
- * Whether this is an index route.
727
- */
728
- index: true;
729
- };
730
- /**
731
- * Non-index routes may have children, but cannot have `index` set to `true`.
732
- */
733
- type NonIndexRouteObject = BaseRouteObject & {
734
- /**
735
- * Child Route objects.
736
- */
737
- children?: RouteObject[];
738
- /**
739
- * Whether this is an index route - must be `false` or undefined on non-index routes.
740
- */
741
- index?: false;
742
- };
743
- /**
744
- * A route object represents a logical route, with (optionally) its child
745
- * routes organized in a tree-like structure.
746
- */
747
- type RouteObject = IndexRouteObject | NonIndexRouteObject;
748
- type DataIndexRouteObject = IndexRouteObject & {
749
- id: string;
750
- };
751
- type DataNonIndexRouteObject = NonIndexRouteObject & {
752
- children?: DataRouteObject[];
753
- id: string;
754
- };
755
- /**
756
- * A data route object, which is just a RouteObject with a required unique ID
757
- */
758
- type DataRouteObject = DataIndexRouteObject | DataNonIndexRouteObject;
759
- type RouteManifest<R = DataRouteObject> = Record<string, R | undefined>;
760
- /**
761
- * The parameters that were parsed from the URL path.
762
- */
763
- type Params<Key extends string = string> = {
764
- readonly [key in Key]: string | undefined;
765
- };
766
- /**
767
- * A RouteMatch contains info about how a route matched a URL.
768
- */
769
- interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> {
770
- /**
771
- * The names and values of dynamic parameters in the URL.
772
- */
773
- params: Params<ParamKey>;
774
- /**
775
- * The portion of the URL pathname that was matched.
776
- */
777
- pathname: string;
778
- /**
779
- * The portion of the URL pathname that was matched before child routes.
780
- */
781
- pathnameBase: string;
782
- /**
783
- * The route object that was used to match.
784
- */
785
- route: RouteObjectType;
786
- }
787
- interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
788
- }
789
- /**
790
- * Matches the given routes to a location and returns the match data.
791
- *
792
- * @example
793
- * import { matchRoutes } from "react-router";
794
- *
795
- * let routes = [{
796
- * path: "/",
797
- * Component: Root,
798
- * children: [{
799
- * path: "dashboard",
800
- * Component: Dashboard,
801
- * }]
802
- * }];
803
- *
804
- * matchRoutes(routes, "/dashboard"); // [rootMatch, dashboardMatch]
805
- *
806
- * @public
807
- * @category Utils
808
- * @param routes The array of route objects to match against.
809
- * @param locationArg The location to match against, either a string path or a
810
- * partial {@link Location} object
811
- * @param basename Optional base path to strip from the location before matching.
812
- * Defaults to `/`.
813
- * @returns An array of matched routes, or `null` if no matches were found.
814
- */
815
- declare function matchRoutes<RouteObjectType extends RouteObject = RouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): RouteMatch<string, RouteObjectType>[] | null;
816
- interface UIMatch<Data = unknown, Handle = unknown> {
817
- id: string;
818
- pathname: string;
819
- /**
820
- * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
821
- */
822
- params: RouteMatch["params"];
823
- /**
824
- * The return value from the matched route's loader or clientLoader. This might
825
- * be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
826
- * an error and we're currently displaying an `ErrorBoundary`.
827
- *
828
- * @deprecated Use `UIMatch.loaderData` instead
829
- */
830
- data: Data | undefined;
831
- /**
832
- * The return value from the matched route's loader or clientLoader. This might
833
- * be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
834
- * an error and we're currently displaying an `ErrorBoundary`.
835
- */
836
- loaderData: Data | undefined;
837
- /**
838
- * The {@link https://reactrouter.com/start/framework/route-module#handle handle object}
839
- * exported from the matched route module
840
- */
841
- handle: Handle;
842
- }
843
- interface RouteMeta<RouteObjectType extends RouteObject = RouteObject> {
844
- relativePath: string;
845
- caseSensitive: boolean;
846
- childrenIndex: number;
847
- route: RouteObjectType;
848
- }
849
- /**
850
- * @private
851
- * PRIVATE - DO NOT USE
852
- *
853
- * A "branch" of routes that match a given route pattern.
854
- * This is an internal interface not intended for direct external usage.
855
- */
856
- interface RouteBranch<RouteObjectType extends RouteObject = RouteObject> {
857
- path: string;
858
- score: number;
859
- routesMeta: RouteMeta<RouteObjectType>[];
860
- }
861
- declare class DataWithResponseInit<D> {
862
- type: string;
863
- data: D;
864
- init: ResponseInit | null;
865
- constructor(data: D, init?: ResponseInit);
866
- }
867
- /**
868
- * Create "responses" that contain `headers`/`status` without forcing
869
- * serialization into an actual [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
870
- *
871
- * @example
872
- * import { data } from "react-router";
873
- *
874
- * export async function action({ request }: Route.ActionArgs) {
875
- * let formData = await request.formData();
876
- * let item = await createItem(formData);
877
- * return data(item, {
878
- * headers: { "X-Custom-Header": "value" }
879
- * status: 201,
880
- * });
881
- * }
882
- *
883
- * @public
884
- * @category Utils
885
- * @mode framework
886
- * @mode data
887
- * @param data The data to be included in the response.
888
- * @param init The status code or a `ResponseInit` object to be included in the
889
- * response.
890
- * @returns A {@link DataWithResponseInit} instance containing the data and
891
- * response init.
892
- */
893
- declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
894
- type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
895
- /**
896
- * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
897
- * Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
898
- * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
899
- *
900
- * This utility accepts absolute URLs and can navigate to external domains, so
901
- * the application should validate any user-supplied inputs to redirects.
902
- *
903
- * @example
904
- * import { redirect } from "react-router";
905
- *
906
- * export async function loader({ request }: Route.LoaderArgs) {
907
- * if (!isLoggedIn(request))
908
- * throw redirect("/login");
909
- * }
910
- *
911
- * // ...
912
- * }
913
- *
914
- * @public
915
- * @category Utils
916
- * @mode framework
917
- * @mode data
918
- * @param url The URL to redirect to.
919
- * @param init The status code or a `ResponseInit` object to be included in the
920
- * response.
921
- * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
922
- * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
923
- * header.
924
- */
925
- declare const redirect$1: RedirectFunction;
926
- /**
927
- * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
928
- * that will force a document reload to the new location. Sets the status code
929
- * and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
930
- * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
931
- *
932
- * This utility accepts absolute URLs and can navigate to external domains, so
933
- * the application should validate any user-supplied inputs to redirects.
934
- *
935
- * ```tsx filename=routes/logout.tsx
936
- * import { redirectDocument } from "react-router";
937
- *
938
- * import { destroySession } from "../sessions.server";
939
- *
940
- * export async function action({ request }: Route.ActionArgs) {
941
- * let session = await getSession(request.headers.get("Cookie"));
942
- * return redirectDocument("/", {
943
- * headers: { "Set-Cookie": await destroySession(session) }
944
- * });
945
- * }
946
- * ```
947
- *
948
- * @public
949
- * @category Utils
950
- * @mode framework
951
- * @mode data
952
- * @param url The URL to redirect to.
953
- * @param init The status code or a `ResponseInit` object to be included in the
954
- * response.
955
- * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
956
- * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
957
- * header.
958
- */
959
- declare const redirectDocument$1: RedirectFunction;
960
- /**
961
- * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
962
- * that will perform a [`history.replaceState`](https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState)
963
- * instead of a [`history.pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
964
- * for client-side navigation redirects. Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
965
- * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
966
- *
967
- * @example
968
- * import { replace } from "react-router";
969
- *
970
- * export async function loader() {
971
- * return replace("/new-location");
972
- * }
973
- *
974
- * @public
975
- * @category Utils
976
- * @mode framework
977
- * @mode data
978
- * @param url The URL to redirect to.
979
- * @param init The status code or a `ResponseInit` object to be included in the
980
- * response.
981
- * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
982
- * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
983
- * header.
984
- */
985
- declare const replace$1: RedirectFunction;
986
- type ErrorResponse = {
987
- status: number;
988
- statusText: string;
989
- data: any;
990
- };
991
- /**
992
- * Check if the given error is an {@link ErrorResponse} generated from a 4xx/5xx
993
- * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
994
- * thrown from an [`action`](../../start/framework/route-module#action) or
995
- * [`loader`](../../start/framework/route-module#loader) function.
996
- *
997
- * @example
998
- * import { isRouteErrorResponse } from "react-router";
999
- *
1000
- * export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
1001
- * if (isRouteErrorResponse(error)) {
1002
- * return (
1003
- * <>
1004
- * <p>Error: `${error.status}: ${error.statusText}`</p>
1005
- * <p>{error.data}</p>
1006
- * </>
1007
- * );
1008
- * }
1009
- *
1010
- * return (
1011
- * <p>Error: {error instanceof Error ? error.message : "Unknown Error"}</p>
1012
- * );
1013
- * }
1014
- *
1015
- * @public
1016
- * @category Utils
1017
- * @mode framework
1018
- * @mode data
1019
- * @param error The error to check.
1020
- * @returns `true` if the error is an {@link ErrorResponse}, `false` otherwise.
1021
- */
1022
- declare function isRouteErrorResponse(error: any): error is ErrorResponse;
1023
-
1024
- /**
1025
- * An object of unknown type for route loaders and actions provided by the
1026
- * server's `getLoadContext()` function. This is defined as an empty interface
1027
- * specifically so apps can leverage declaration merging to augment this type
1028
- * globally: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
1029
- */
1030
- interface AppLoadContext {
1031
- [key: string]: unknown;
1032
- }
1033
-
1034
- type ServerInstrumentation = {
1035
- handler?: InstrumentRequestHandlerFunction;
1036
- route?: InstrumentRouteFunction;
1037
- };
1038
- type ClientInstrumentation = {
1039
- router?: InstrumentRouterFunction;
1040
- route?: InstrumentRouteFunction;
1041
- };
1042
- type InstrumentRequestHandlerFunction = (handler: InstrumentableRequestHandler) => void;
1043
- type InstrumentRouterFunction = (router: InstrumentableRouter) => void;
1044
- type InstrumentRouteFunction = (route: InstrumentableRoute) => void;
1045
- type InstrumentationHandlerResult = {
1046
- status: "success";
1047
- error: undefined;
1048
- } | {
1049
- status: "error";
1050
- error: Error;
1051
- };
1052
- type InstrumentFunction<T> = (handler: () => Promise<InstrumentationHandlerResult>, info: T) => Promise<void>;
1053
- type ReadonlyRequest = {
1054
- method: string;
1055
- url: string;
1056
- headers: Pick<Headers, "get">;
1057
- };
1058
- type ReadonlyContext = MiddlewareEnabled extends true ? Pick<RouterContextProvider, "get"> : Readonly<AppLoadContext>;
1059
- type InstrumentableRoute = {
1060
- id: string;
1061
- index: boolean | undefined;
1062
- path: string | undefined;
1063
- instrument(instrumentations: RouteInstrumentations): void;
1064
- };
1065
- type RouteInstrumentations = {
1066
- lazy?: InstrumentFunction<RouteLazyInstrumentationInfo>;
1067
- "lazy.loader"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
1068
- "lazy.action"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
1069
- "lazy.middleware"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
1070
- middleware?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
1071
- loader?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
1072
- action?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
1073
- };
1074
- type RouteLazyInstrumentationInfo = undefined;
1075
- type RouteHandlerInstrumentationInfo = Readonly<{
1076
- request: ReadonlyRequest;
1077
- params: LoaderFunctionArgs["params"];
1078
- pattern: string;
1079
- context: ReadonlyContext;
1080
- }>;
1081
- type InstrumentableRouter = {
1082
- instrument(instrumentations: RouterInstrumentations): void;
1083
- };
1084
- type RouterInstrumentations = {
1085
- navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo>;
1086
- fetch?: InstrumentFunction<RouterFetchInstrumentationInfo>;
1087
- };
1088
- type RouterNavigationInstrumentationInfo = Readonly<{
1089
- to: string | number;
1090
- currentUrl: string;
1091
- formMethod?: HTMLFormMethod;
1092
- formEncType?: FormEncType;
1093
- formData?: FormData;
1094
- body?: any;
1095
- }>;
1096
- type RouterFetchInstrumentationInfo = Readonly<{
1097
- href: string;
1098
- currentUrl: string;
1099
- fetcherKey: string;
1100
- formMethod?: HTMLFormMethod;
1101
- formEncType?: FormEncType;
1102
- formData?: FormData;
1103
- body?: any;
1104
- }>;
1105
- type InstrumentableRequestHandler = {
1106
- instrument(instrumentations: RequestHandlerInstrumentations): void;
1107
- };
1108
- type RequestHandlerInstrumentations = {
1109
- request?: InstrumentFunction<RequestHandlerInstrumentationInfo>;
1110
- };
1111
- type RequestHandlerInstrumentationInfo = Readonly<{
1112
- request: ReadonlyRequest;
1113
- context: ReadonlyContext | undefined;
1114
- }>;
1115
-
1116
- /**
1117
- * A Router instance manages all navigation and data loading/mutations
1118
- */
1119
- interface Router {
1120
- /**
1121
- * @private
1122
- * PRIVATE - DO NOT USE
1123
- *
1124
- * Return the basename for the router
1125
- */
1126
- get basename(): RouterInit["basename"];
1127
- /**
1128
- * @private
1129
- * PRIVATE - DO NOT USE
1130
- *
1131
- * Return the future config for the router
1132
- */
1133
- get future(): FutureConfig;
1134
- /**
1135
- * @private
1136
- * PRIVATE - DO NOT USE
1137
- *
1138
- * Return the current state of the router
1139
- */
1140
- get state(): RouterState;
1141
- /**
1142
- * @private
1143
- * PRIVATE - DO NOT USE
1144
- *
1145
- * Return the routes for this router instance
1146
- */
1147
- get routes(): DataRouteObject[];
1148
- /**
1149
- * @private
1150
- * PRIVATE - DO NOT USE
1151
- *
1152
- * Return the route branches for this router instance
1153
- */
1154
- get branches(): RouteBranch<DataRouteObject>[] | undefined;
1155
- /**
1156
- * @private
1157
- * PRIVATE - DO NOT USE
1158
- *
1159
- * Return the manifest for this router instance
1160
- */
1161
- get manifest(): RouteManifest;
1162
- /**
1163
- * @private
1164
- * PRIVATE - DO NOT USE
1165
- *
1166
- * Return the window associated with the router
1167
- */
1168
- get window(): RouterInit["window"];
1169
- /**
1170
- * @private
1171
- * PRIVATE - DO NOT USE
1172
- *
1173
- * Initialize the router, including adding history listeners and kicking off
1174
- * initial data fetches. Returns a function to cleanup listeners and abort
1175
- * any in-progress loads
1176
- */
1177
- initialize(): Router;
1178
- /**
1179
- * @private
1180
- * PRIVATE - DO NOT USE
1181
- *
1182
- * Subscribe to router.state updates
1183
- *
1184
- * @param fn function to call with the new state
1185
- */
1186
- subscribe(fn: RouterSubscriber): () => void;
1187
- /**
1188
- * @private
1189
- * PRIVATE - DO NOT USE
1190
- *
1191
- * Enable scroll restoration behavior in the router
1192
- *
1193
- * @param savedScrollPositions Object that will manage positions, in case
1194
- * it's being restored from sessionStorage
1195
- * @param getScrollPosition Function to get the active Y scroll position
1196
- * @param getKey Function to get the key to use for restoration
1197
- */
1198
- enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
1199
- /**
1200
- * @private
1201
- * PRIVATE - DO NOT USE
1202
- *
1203
- * Navigate forward/backward in the history stack
1204
- * @param to Delta to move in the history stack
1205
- */
1206
- navigate(to: number): Promise<void>;
1207
- /**
1208
- * Navigate to the given path
1209
- * @param to Path to navigate to
1210
- * @param opts Navigation options (method, submission, etc.)
1211
- */
1212
- navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
1213
- /**
1214
- * @private
1215
- * PRIVATE - DO NOT USE
1216
- *
1217
- * Trigger a fetcher load/submission
1218
- *
1219
- * @param key Fetcher key
1220
- * @param routeId Route that owns the fetcher
1221
- * @param href href to fetch
1222
- * @param opts Fetcher options, (method, submission, etc.)
1223
- */
1224
- fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
1225
- /**
1226
- * @private
1227
- * PRIVATE - DO NOT USE
1228
- *
1229
- * Trigger a revalidation of all current route loaders and fetcher loads
1230
- */
1231
- revalidate(): Promise<void>;
1232
- /**
1233
- * @private
1234
- * PRIVATE - DO NOT USE
1235
- *
1236
- * Utility function to create an href for the given location
1237
- * @param location
1238
- */
1239
- createHref(location: Location | URL): string;
1240
- /**
1241
- * @private
1242
- * PRIVATE - DO NOT USE
1243
- *
1244
- * Utility function to URL encode a destination path according to the internal
1245
- * history implementation
1246
- * @param to
1247
- */
1248
- encodeLocation(to: To): Path;
1249
- /**
1250
- * @private
1251
- * PRIVATE - DO NOT USE
1252
- *
1253
- * Get/create a fetcher for the given key
1254
- * @param key
1255
- */
1256
- getFetcher<TData = any>(key: string): Fetcher<TData>;
1257
- /**
1258
- * @internal
1259
- * PRIVATE - DO NOT USE
1260
- *
1261
- * Reset the fetcher for a given key
1262
- * @param key
1263
- */
1264
- resetFetcher(key: string, opts?: {
1265
- reason?: unknown;
1266
- }): void;
1267
- /**
1268
- * @private
1269
- * PRIVATE - DO NOT USE
1270
- *
1271
- * Delete the fetcher for a given key
1272
- * @param key
1273
- */
1274
- deleteFetcher(key: string): void;
1275
- /**
1276
- * @private
1277
- * PRIVATE - DO NOT USE
1278
- *
1279
- * Cleanup listeners and abort any in-progress loads
1280
- */
1281
- dispose(): void;
1282
- /**
1283
- * @private
1284
- * PRIVATE - DO NOT USE
1285
- *
1286
- * Get a navigation blocker
1287
- * @param key The identifier for the blocker
1288
- * @param fn The blocker function implementation
1289
- */
1290
- getBlocker(key: string, fn: BlockerFunction): Blocker;
1291
- /**
1292
- * @private
1293
- * PRIVATE - DO NOT USE
1294
- *
1295
- * Delete a navigation blocker
1296
- * @param key The identifier for the blocker
1297
- */
1298
- deleteBlocker(key: string): void;
1299
- /**
1300
- * @private
1301
- * PRIVATE DO NOT USE
1302
- *
1303
- * Patch additional children routes into an existing parent route
1304
- * @param routeId The parent route id or a callback function accepting `patch`
1305
- * to perform batch patching
1306
- * @param children The additional children routes
1307
- * @param unstable_allowElementMutations Allow mutation or route elements on
1308
- * existing routes. Intended for RSC-usage
1309
- * only.
1310
- */
1311
- patchRoutes(routeId: string | null, children: RouteObject[], unstable_allowElementMutations?: boolean): void;
1312
- /**
1313
- * @private
1314
- * PRIVATE - DO NOT USE
1315
- *
1316
- * HMR needs to pass in-flight route updates to React Router
1317
- * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
1318
- */
1319
- _internalSetRoutes(routes: RouteObject[]): void;
1320
- /**
1321
- * @private
1322
- * PRIVATE - DO NOT USE
1323
- *
1324
- * Cause subscribers to re-render. This is used to force a re-render.
1325
- */
1326
- _internalSetStateDoNotUseOrYouWillBreakYourApp(state: Partial<RouterState>): void;
1327
- /**
1328
- * @private
1329
- * PRIVATE - DO NOT USE
1330
- *
1331
- * Internal fetch AbortControllers accessed by unit tests
1332
- */
1333
- _internalFetchControllers: Map<string, AbortController>;
1334
- }
1335
- /**
1336
- * State maintained internally by the router. During a navigation, all states
1337
- * reflect the "old" location unless otherwise noted.
1338
- */
1339
- interface RouterState {
1340
- /**
1341
- * The action of the most recent navigation
1342
- */
1343
- historyAction: Action;
1344
- /**
1345
- * The current location reflected by the router
1346
- */
1347
- location: Location;
1348
- /**
1349
- * The current set of route matches
1350
- */
1351
- matches: DataRouteMatch[];
1352
- /**
1353
- * Tracks whether we've completed our initial data load
1354
- */
1355
- initialized: boolean;
1356
- /**
1357
- * Tracks whether we should be rendering a HydrateFallback during hydration
1358
- */
1359
- renderFallback: boolean;
1360
- /**
1361
- * Current scroll position we should start at for a new view
1362
- * - number -> scroll position to restore to
1363
- * - false -> do not restore scroll at all (used during submissions/revalidations)
1364
- * - null -> don't have a saved position, scroll to hash or top of page
1365
- */
1366
- restoreScrollPosition: number | false | null;
1367
- /**
1368
- * Indicate whether this navigation should skip resetting the scroll position
1369
- * if we are unable to restore the scroll position
1370
- */
1371
- preventScrollReset: boolean;
1372
- /**
1373
- * Tracks the state of the current navigation
1374
- */
1375
- navigation: Navigation;
1376
- /**
1377
- * Tracks any in-progress revalidations
1378
- */
1379
- revalidation: RevalidationState;
1380
- /**
1381
- * Data from the loaders for the current matches
1382
- */
1383
- loaderData: RouteData;
1384
- /**
1385
- * Data from the action for the current matches
1386
- */
1387
- actionData: RouteData | null;
1388
- /**
1389
- * Errors caught from loaders for the current matches
1390
- */
1391
- errors: RouteData | null;
1392
- /**
1393
- * Map of current fetchers
1394
- */
1395
- fetchers: Map<string, Fetcher>;
1396
- /**
1397
- * Map of current blockers
1398
- */
1399
- blockers: Map<string, Blocker>;
1400
- }
1401
- /**
1402
- * Data that can be passed into hydrate a Router from SSR
1403
- */
1404
- type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
1405
- /**
1406
- * Future flags to toggle new feature behavior
1407
- */
1408
- interface FutureConfig {
1409
- }
1410
- /**
1411
- * Initialization options for createRouter
1412
- */
1413
- interface RouterInit {
1414
- routes: RouteObject[];
1415
- history: History;
1416
- basename?: string;
1417
- getContext?: () => MaybePromise<RouterContextProvider>;
1418
- instrumentations?: ClientInstrumentation[];
1419
- mapRouteProperties?: MapRoutePropertiesFunction;
1420
- future?: Partial<FutureConfig>;
1421
- hydrationRouteProperties?: string[];
1422
- hydrationData?: HydrationState;
1423
- window?: Window;
1424
- dataStrategy?: DataStrategyFunction;
1425
- patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
1426
- }
1427
- /**
1428
- * State returned from a server-side query() call
1429
- */
1430
- interface StaticHandlerContext {
1431
- basename: Router["basename"];
1432
- location: RouterState["location"];
1433
- matches: RouterState["matches"];
1434
- loaderData: RouterState["loaderData"];
1435
- actionData: RouterState["actionData"];
1436
- errors: RouterState["errors"];
1437
- statusCode: number;
1438
- loaderHeaders: Record<string, Headers>;
1439
- actionHeaders: Record<string, Headers>;
1440
- _deepestRenderedBoundaryId?: string | null;
1441
- }
1442
- /**
1443
- * A StaticHandler instance manages a singular SSR navigation/fetch event
1444
- */
1445
- interface StaticHandler {
1446
- /**
1447
- * The set of data routes managed by this handler
1448
- */
1449
- dataRoutes: DataRouteObject[];
1450
- /**
1451
- * @private
1452
- * PRIVATE - DO NOT USE
1453
- *
1454
- * The route branches derived from the data routes, used for internal route
1455
- * matching in Framework Mode
1456
- */
1457
- _internalRouteBranches: RouteBranch<DataRouteObject>[];
1458
- /**
1459
- * Perform a query for a given request - executing all matched route
1460
- * loaders/actions. Used for document requests.
1461
- *
1462
- * @param request The request to query
1463
- * @param opts Optional query options
1464
- * @param opts.dataStrategy Alternate dataStrategy implementation
1465
- * @param opts.filterMatchesToLoad Predicate function to filter which matches should be loaded
1466
- * @param opts.generateMiddlewareResponse To enable middleware, provide a function
1467
- * to generate a response to bubble back up the middleware chain
1468
- * @param opts.requestContext Context object to pass to loaders/actions
1469
- * @param opts.skipLoaderErrorBubbling Skip loader error bubbling
1470
- * @param opts.skipRevalidation Skip revalidation after action submission
1471
- * @param opts.normalizePath Normalize the request path
1472
- */
1473
- query(request: Request, opts?: {
1474
- requestContext?: unknown;
1475
- filterMatchesToLoad?: (match: DataRouteMatch) => boolean;
1476
- skipLoaderErrorBubbling?: boolean;
1477
- skipRevalidation?: boolean;
1478
- dataStrategy?: DataStrategyFunction<unknown>;
1479
- generateMiddlewareResponse?: (query: (r: Request, args?: {
1480
- filterMatchesToLoad?: (match: DataRouteMatch) => boolean;
1481
- }) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
1482
- normalizePath?: (request: Request) => Path;
1483
- }): Promise<StaticHandlerContext | Response>;
1484
- /**
1485
- * Perform a query for a specific route. Used for resource requests.
1486
- *
1487
- * @param request The request to query
1488
- * @param opts Optional queryRoute options
1489
- * @param opts.dataStrategy Alternate dataStrategy implementation
1490
- * @param opts.generateMiddlewareResponse To enable middleware, provide a function
1491
- * to generate a response to bubble back up the middleware chain
1492
- * @param opts.requestContext Context object to pass to loaders/actions
1493
- * @param opts.routeId The ID of the route to query
1494
- * @param opts.normalizePath Normalize the request path
1495
-
1496
- */
1497
- queryRoute(request: Request, opts?: {
1498
- routeId?: string;
1499
- requestContext?: unknown;
1500
- dataStrategy?: DataStrategyFunction<unknown>;
1501
- generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
1502
- normalizePath?: (request: Request) => Path;
1503
- }): Promise<any>;
1504
- }
1505
- type ViewTransitionOpts = {
1506
- currentLocation: Location;
1507
- nextLocation: Location;
1508
- };
1509
- /**
1510
- * Subscriber function signature for changes to router state
1511
- */
1512
- interface RouterSubscriber {
1513
- (state: RouterState, opts: {
1514
- deletedFetchers: string[];
1515
- newErrors: RouteData | null;
1516
- viewTransitionOpts?: ViewTransitionOpts;
1517
- flushSync: boolean;
1518
- }): void;
1519
- }
1520
- /**
1521
- * Function signature for determining the key to be used in scroll restoration
1522
- * for a given location
1523
- */
1524
- interface GetScrollRestorationKeyFunction {
1525
- (location: Location, matches: UIMatch[]): string | null;
1526
- }
1527
- /**
1528
- * Function signature for determining the current scroll position
1529
- */
1530
- interface GetScrollPositionFunction {
1531
- (): number;
1532
- }
1533
- /**
1534
- * - "route": relative to the route hierarchy so `..` means remove all segments
1535
- * of the current route even if it has many. For example, a `route("posts/:id")`
1536
- * would have both `:id` and `posts` removed from the url.
1537
- * - "path": relative to the pathname so `..` means remove one segment of the
1538
- * pathname. For example, a `route("posts/:id")` would have only `:id` removed
1539
- * from the url.
1540
- */
1541
- type RelativeRoutingType = "route" | "path";
1542
- type BaseNavigateOrFetchOptions = {
1543
- preventScrollReset?: boolean;
1544
- relative?: RelativeRoutingType;
1545
- flushSync?: boolean;
1546
- defaultShouldRevalidate?: boolean;
1547
- };
1548
- type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
1549
- replace?: boolean;
1550
- state?: any;
1551
- fromRouteId?: string;
1552
- viewTransition?: boolean;
1553
- mask?: To;
1554
- };
1555
- type BaseSubmissionOptions = {
1556
- formMethod?: HTMLFormMethod;
1557
- formEncType?: FormEncType;
1558
- } & ({
1559
- formData: FormData;
1560
- body?: undefined;
1561
- } | {
1562
- formData?: undefined;
1563
- body: any;
1564
- });
1565
- /**
1566
- * Options for a navigate() call for a normal (non-submission) navigation
1567
- */
1568
- type LinkNavigateOptions = BaseNavigateOptions;
1569
- /**
1570
- * Options for a navigate() call for a submission navigation
1571
- */
1572
- type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
1573
- /**
1574
- * Options to pass to navigate() for a navigation
1575
- */
1576
- type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
1577
- /**
1578
- * Options for a fetch() load
1579
- */
1580
- type LoadFetchOptions = BaseNavigateOrFetchOptions;
1581
- /**
1582
- * Options for a fetch() submission
1583
- */
1584
- type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
1585
- /**
1586
- * Options to pass to fetch()
1587
- */
1588
- type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
1589
- /**
1590
- * Potential states for state.navigation
1591
- */
1592
- type NavigationStates = {
1593
- Idle: {
1594
- state: "idle";
1595
- location: undefined;
1596
- matches: undefined;
1597
- historyAction: undefined;
1598
- formMethod: undefined;
1599
- formAction: undefined;
1600
- formEncType: undefined;
1601
- formData: undefined;
1602
- json: undefined;
1603
- text: undefined;
1604
- };
1605
- Loading: {
1606
- state: "loading";
1607
- location: Location;
1608
- matches: DataRouteMatch[];
1609
- historyAction: Action;
1610
- formMethod: Submission["formMethod"] | undefined;
1611
- formAction: Submission["formAction"] | undefined;
1612
- formEncType: Submission["formEncType"] | undefined;
1613
- formData: Submission["formData"] | undefined;
1614
- json: Submission["json"] | undefined;
1615
- text: Submission["text"] | undefined;
1616
- };
1617
- Submitting: {
1618
- state: "submitting";
1619
- location: Location;
1620
- matches: DataRouteMatch[];
1621
- historyAction: Action;
1622
- formMethod: Submission["formMethod"];
1623
- formAction: Submission["formAction"];
1624
- formEncType: Submission["formEncType"];
1625
- formData: Submission["formData"];
1626
- json: Submission["json"];
1627
- text: Submission["text"];
1628
- };
1629
- };
1630
- type Navigation = NavigationStates[keyof NavigationStates];
1631
- type RevalidationState = "idle" | "loading";
1632
- /**
1633
- * Potential states for fetchers
1634
- */
1635
- type FetcherStates<TData = any> = {
1636
- /**
1637
- * The fetcher is not calling a loader or action
1638
- *
1639
- * ```tsx
1640
- * fetcher.state === "idle"
1641
- * ```
1642
- */
1643
- Idle: {
1644
- state: "idle";
1645
- formMethod: undefined;
1646
- formAction: undefined;
1647
- formEncType: undefined;
1648
- text: undefined;
1649
- formData: undefined;
1650
- json: undefined;
1651
- /**
1652
- * If the fetcher has never been called, this will be undefined.
1653
- */
1654
- data: TData | undefined;
1655
- };
1656
- /**
1657
- * The fetcher is loading data from a {@link LoaderFunction | loader} from a
1658
- * call to {@link FetcherWithComponents.load | `fetcher.load`}.
1659
- *
1660
- * ```tsx
1661
- * // somewhere
1662
- * <button onClick={() => fetcher.load("/some/route") }>Load</button>
1663
- *
1664
- * // the state will update
1665
- * fetcher.state === "loading"
1666
- * ```
1667
- */
1668
- Loading: {
1669
- state: "loading";
1670
- formMethod: Submission["formMethod"] | undefined;
1671
- formAction: Submission["formAction"] | undefined;
1672
- formEncType: Submission["formEncType"] | undefined;
1673
- text: Submission["text"] | undefined;
1674
- formData: Submission["formData"] | undefined;
1675
- json: Submission["json"] | undefined;
1676
- data: TData | undefined;
1677
- };
1678
- /**
1679
- 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`}.
1680
-
1681
- ```tsx
1682
- // somewhere
1683
- <input
1684
- onChange={e => {
1685
- fetcher.submit(event.currentTarget.form, { method: "post" });
1686
- }}
1687
- />
1688
-
1689
- // the state will update
1690
- fetcher.state === "submitting"
1691
-
1692
- // and formData will be available
1693
- fetcher.formData
1694
- ```
1695
- */
1696
- Submitting: {
1697
- state: "submitting";
1698
- formMethod: Submission["formMethod"];
1699
- formAction: Submission["formAction"];
1700
- formEncType: Submission["formEncType"];
1701
- text: Submission["text"];
1702
- formData: Submission["formData"];
1703
- json: Submission["json"];
1704
- data: TData | undefined;
1705
- };
1706
- };
1707
- type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
1708
- interface BlockerBlocked {
1709
- state: "blocked";
1710
- reset: () => void;
1711
- proceed: () => void;
1712
- location: Location;
1713
- }
1714
- interface BlockerUnblocked {
1715
- state: "unblocked";
1716
- reset: undefined;
1717
- proceed: undefined;
1718
- location: undefined;
1719
- }
1720
- interface BlockerProceeding {
1721
- state: "proceeding";
1722
- reset: undefined;
1723
- proceed: undefined;
1724
- location: Location;
1725
- }
1726
- type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
1727
- type BlockerFunction = (args: {
1728
- currentLocation: Location;
1729
- nextLocation: Location;
1730
- historyAction: Action;
1731
- }) => boolean;
1732
- interface CreateStaticHandlerOptions {
1733
- basename?: string;
1734
- mapRouteProperties?: MapRoutePropertiesFunction;
1735
- instrumentations?: Pick<ServerInstrumentation, "route">[];
1736
- future?: Partial<FutureConfig>;
1737
- }
1738
- declare function createStaticHandler(routes: RouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
1739
-
1740
- type Primitive = null | undefined | string | number | boolean | symbol | bigint;
1741
- type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
1742
- interface HtmlLinkProps {
1743
- /**
1744
- * Address of the hyperlink
1745
- */
1746
- href?: string;
1747
- /**
1748
- * How the element handles crossorigin requests
1749
- */
1750
- crossOrigin?: "anonymous" | "use-credentials";
1751
- /**
1752
- * Relationship between the document containing the hyperlink and the destination resource
1753
- */
1754
- rel: LiteralUnion<"alternate" | "dns-prefetch" | "icon" | "manifest" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "search" | "stylesheet", string>;
1755
- /**
1756
- * Applicable media: "screen", "print", "(max-width: 764px)"
1757
- */
1758
- media?: string;
1759
- /**
1760
- * Integrity metadata used in Subresource Integrity checks
1761
- */
1762
- integrity?: string;
1763
- /**
1764
- * Language of the linked resource
1765
- */
1766
- hrefLang?: string;
1767
- /**
1768
- * Hint for the type of the referenced resource
1769
- */
1770
- type?: string;
1771
- /**
1772
- * Referrer policy for fetches initiated by the element
1773
- */
1774
- referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
1775
- /**
1776
- * Sizes of the icons (for rel="icon")
1777
- */
1778
- sizes?: string;
1779
- /**
1780
- * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1781
- */
1782
- as?: LiteralUnion<"audio" | "audioworklet" | "document" | "embed" | "fetch" | "font" | "frame" | "iframe" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt", string>;
1783
- /**
1784
- * Color to use when customizing a site's icon (for rel="mask-icon")
1785
- */
1786
- color?: string;
1787
- /**
1788
- * Whether the link is disabled
1789
- */
1790
- disabled?: boolean;
1791
- /**
1792
- * The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
1793
- */
1794
- title?: string;
1795
- /**
1796
- * Images to use in different situations, e.g., high-resolution displays,
1797
- * small monitors, etc. (for rel="preload")
1798
- */
1799
- imageSrcSet?: string;
1800
- /**
1801
- * Image sizes for different page layouts (for rel="preload")
1802
- */
1803
- imageSizes?: string;
1804
- }
1805
- interface HtmlLinkPreloadImage extends HtmlLinkProps {
1806
- /**
1807
- * Relationship between the document containing the hyperlink and the destination resource
1808
- */
1809
- rel: "preload";
1810
- /**
1811
- * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1812
- */
1813
- as: "image";
1814
- /**
1815
- * Address of the hyperlink
1816
- */
1817
- href?: string;
1818
- /**
1819
- * Images to use in different situations, e.g., high-resolution displays,
1820
- * small monitors, etc. (for rel="preload")
1821
- */
1822
- imageSrcSet: string;
1823
- /**
1824
- * Image sizes for different page layouts (for rel="preload")
1825
- */
1826
- imageSizes?: string;
1827
- }
1828
- /**
1829
- * Represents a `<link>` element.
1830
- *
1831
- * WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
1832
- */
1833
- type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "href"> & {
1834
- imageSizes?: never;
1835
- });
1836
- interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
1837
- /**
1838
- * A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
1839
- * attribute to render on the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
1840
- * element
1841
- */
1842
- nonce?: string | undefined;
1843
- /**
1844
- * The absolute path of the page to prefetch, e.g. `/absolute/path`.
1845
- */
1846
- page: string;
1847
- }
1848
- type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
1849
-
1850
- type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
1851
- [key: PropertyKey]: Serializable;
1852
- } | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
1853
-
1854
- type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
1855
- type IsAny<T> = 0 extends 1 & T ? true : false;
1856
- type Func = (...args: any[]) => unknown;
1857
-
1858
- /**
1859
- * A brand that can be applied to a type to indicate that it will serialize
1860
- * to a specific type when transported to the client from a loader.
1861
- * Only use this if you have additional serialization/deserialization logic
1862
- * in your application.
1863
- */
1864
- type unstable_SerializesTo<T> = {
1865
- unstable__ReactRouter_SerializesTo: [T];
1866
- };
1867
-
1868
- type Serialize<T> = T extends unstable_SerializesTo<infer To> ? To : T extends Serializable ? T : T extends (...args: any[]) => unknown ? undefined : T extends Promise<infer U> ? Promise<Serialize<U>> : T extends Map<infer K, infer V> ? Map<Serialize<K>, Serialize<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<Serialize<K>, Serialize<V>> : T extends Set<infer U> ? Set<Serialize<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<Serialize<U>> : T extends [] ? [] : T extends readonly [infer F, ...infer R] ? [Serialize<F>, ...Serialize<R>] : T extends Array<infer U> ? Array<Serialize<U>> : T extends readonly unknown[] ? readonly Serialize<T[number]>[] : T extends Record<any, any> ? {
1869
- [K in keyof T]: Serialize<T[K]>;
1870
- } : undefined;
1871
- type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
1872
- type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
1873
- type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
1874
- type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
1875
- type ServerDataFrom<T> = ServerData<DataFrom<T>>;
1876
- type ClientDataFrom<T> = ClientData<DataFrom<T>>;
1877
- type ClientDataFunctionArgs<Params> = {
1878
- /**
1879
- * A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the URL, the method, the "content-type" header, and the request body from the request.
1880
- *
1881
- * @note Because client data functions are called before a network request is made, the Request object does not include the headers which the browser automatically adds. React Router infers the "content-type" header from the enc-type of the form that performed the submission.
1882
- **/
1883
- request: Request;
1884
- /**
1885
- * A URL instance representing the application location being navigated to or
1886
- * fetched. By default, this matches `request.url`.
1887
- *
1888
- * In Framework mode with `future.v8_passThroughRequests` enabled, this is a
1889
- * normalized URL with React-Router-specific implementation details removed
1890
- * (`.data` suffixes, `index`/`_routes` search params).
1891
- */
1892
- url: URL;
1893
- /**
1894
- * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
1895
- * @example
1896
- * // app/routes.ts
1897
- * route("teams/:teamId", "./team.tsx"),
1898
- *
1899
- * // app/team.tsx
1900
- * export function clientLoader({
1901
- * params,
1902
- * }: Route.ClientLoaderArgs) {
1903
- * params.teamId;
1904
- * // ^ string
1905
- * }
1906
- **/
1907
- params: Params;
1908
- /**
1909
- * Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
1910
- * Mostly useful as a identifier to aggregate on for logging/tracing/etc.
1911
- */
1912
- pattern: string;
1913
- /**
1914
- * When `future.v8_middleware` is not enabled, this is undefined.
1915
- *
1916
- * When `future.v8_middleware` is enabled, this is an instance of
1917
- * `RouterContextProvider` and can be used to access context values
1918
- * from your route middlewares. You may pass in initial context values in your
1919
- * `<HydratedRouter getContext>` prop
1920
- */
1921
- context: Readonly<RouterContextProvider>;
1922
- };
1923
- type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [
1924
- ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>
1925
- ] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
1926
-
1927
- /**
1928
- * A function that handles data mutations for a route on the client
1929
- */
1930
- type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<ActionFunction>;
1931
- /**
1932
- * Arguments passed to a route `clientAction` function
1933
- */
1934
- type ClientActionFunctionArgs = ActionFunctionArgs & {
1935
- serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
1936
- };
1937
- /**
1938
- * A function that loads data for a route on the client
1939
- */
1940
- type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<LoaderFunction>) & {
1941
- hydrate?: boolean;
1942
- };
1943
- /**
1944
- * Arguments passed to a route `clientLoader` function
1945
- */
1946
- type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
1947
- serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
1948
- };
1949
- type HeadersArgs = {
1950
- loaderHeaders: Headers;
1951
- parentHeaders: Headers;
1952
- actionHeaders: Headers;
1953
- errorHeaders: Headers | undefined;
1954
- };
1955
- /**
1956
- * A function that returns HTTP headers to be used for a route. These headers
1957
- * will be merged with (and take precedence over) headers from parent routes.
1958
- */
1959
- interface HeadersFunction {
1960
- (args: HeadersArgs): Headers | HeadersInit;
1961
- }
1962
- /**
1963
- * A function that defines `<link>` tags to be inserted into the `<head>` of
1964
- * the document on route transitions.
1965
- *
1966
- * @see https://reactrouter.com/start/framework/route-module#meta
1967
- */
1968
- interface LinksFunction {
1969
- (): LinkDescriptor[];
1970
- }
1971
- interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
1972
- id: RouteId;
1973
- pathname: DataRouteMatch["pathname"];
1974
- /** @deprecated Use `MetaMatch.loaderData` instead */
1975
- data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
1976
- loaderData: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
1977
- handle?: RouteHandle;
1978
- params: DataRouteMatch["params"];
1979
- meta: MetaDescriptor[];
1980
- error?: unknown;
1981
- }
1982
- type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> = Array<{
1983
- [K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
1984
- }[keyof MatchLoaders]>;
1985
- interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1986
- /** @deprecated Use `MetaArgs.loaderData` instead */
1987
- data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
1988
- loaderData: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
1989
- params: Params;
1990
- location: Location;
1991
- matches: MetaMatches<MatchLoaders>;
1992
- error?: unknown;
1993
- }
1994
- /**
1995
- * A function that returns an array of data objects to use for rendering
1996
- * metadata HTML tags in a route. These tags are not rendered on descendant
1997
- * routes in the route hierarchy. In other words, they will only be rendered on
1998
- * the route in which they are exported.
1999
- *
2000
- * @param Loader - The type of the current route's loader function
2001
- * @param MatchLoaders - Mapping from a parent route's filepath to its loader
2002
- * function type
2003
- *
2004
- * Note that parent route filepaths are relative to the `app/` directory.
2005
- *
2006
- * For example, if this meta function is for `/sales/customers/$customerId`:
2007
- *
2008
- * ```ts
2009
- * // app/root.tsx
2010
- * const loader = () => ({ hello: "world" })
2011
- * export type Loader = typeof loader
2012
- *
2013
- * // app/routes/sales.tsx
2014
- * const loader = () => ({ salesCount: 1074 })
2015
- * export type Loader = typeof loader
2016
- *
2017
- * // app/routes/sales/customers.tsx
2018
- * const loader = () => ({ customerCount: 74 })
2019
- * export type Loader = typeof loader
2020
- *
2021
- * // app/routes/sales/customers/$customersId.tsx
2022
- * import type { Loader as RootLoader } from "../../../root"
2023
- * import type { Loader as SalesLoader } from "../../sales"
2024
- * import type { Loader as CustomersLoader } from "../../sales/customers"
2025
- *
2026
- * const loader = () => ({ name: "Customer name" })
2027
- *
2028
- * const meta: MetaFunction<typeof loader, {
2029
- * "root": RootLoader,
2030
- * "routes/sales": SalesLoader,
2031
- * "routes/sales/customers": CustomersLoader,
2032
- * }> = ({ data, matches }) => {
2033
- * const { name } = data
2034
- * // ^? string
2035
- * const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
2036
- * // ^? number
2037
- * const { salesCount } = matches.find((match) => match.id === "routes/sales").data
2038
- * // ^? number
2039
- * const { hello } = matches.find((match) => match.id === "root").data
2040
- * // ^? "world"
2041
- * }
2042
- * ```
2043
- */
2044
- interface MetaFunction<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
2045
- (args: MetaArgs<Loader, MatchLoaders>): MetaDescriptor[] | undefined;
2046
- }
2047
- type MetaDescriptor = {
2048
- charSet: "utf-8";
2049
- } | {
2050
- title: string;
2051
- } | {
2052
- name: string;
2053
- content: string;
2054
- } | {
2055
- property: string;
2056
- content: string;
2057
- } | {
2058
- httpEquiv: string;
2059
- content: string;
2060
- } | {
2061
- "script:ld+json": LdJsonObject;
2062
- } | {
2063
- tagName: "meta" | "link";
2064
- [name: string]: string;
2065
- } | {
2066
- [name: string]: unknown;
2067
- };
2068
- type LdJsonObject = {
2069
- [Key in string]: LdJsonValue;
2070
- } & {
2071
- [Key in string]?: LdJsonValue | undefined;
2072
- };
2073
- type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
2074
- type LdJsonPrimitive = string | number | boolean | null;
2075
- type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
2076
- /**
2077
- * An arbitrary object that is associated with a route.
2078
- *
2079
- * @see https://reactrouter.com/how-to/using-handle
2080
- */
2081
- type RouteHandle = unknown;
2082
-
2083
- interface AwaitResolveRenderFunction<Resolve = any> {
2084
- (data: Awaited<Resolve>): React.ReactNode;
2085
- }
2086
- /**
2087
- * @category Types
2088
- */
2089
- interface AwaitProps<Resolve> {
2090
- /**
2091
- * When using a function, the resolved value is provided as the parameter.
2092
- *
2093
- * ```tsx [2]
2094
- * <Await resolve={reviewsPromise}>
2095
- * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
2096
- * </Await>
2097
- * ```
2098
- *
2099
- * When using React elements, {@link useAsyncValue} will provide the
2100
- * resolved value:
2101
- *
2102
- * ```tsx [2]
2103
- * <Await resolve={reviewsPromise}>
2104
- * <Reviews />
2105
- * </Await>
2106
- *
2107
- * function Reviews() {
2108
- * const resolvedReviews = useAsyncValue();
2109
- * return <div>...</div>;
2110
- * }
2111
- * ```
2112
- */
2113
- children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
2114
- /**
2115
- * The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
2116
- * rejects.
2117
- *
2118
- * ```tsx
2119
- * <Await
2120
- * errorElement={<div>Oops</div>}
2121
- * resolve={reviewsPromise}
2122
- * >
2123
- * <Reviews />
2124
- * </Await>
2125
- * ```
2126
- *
2127
- * To provide a more contextual error, you can use the {@link useAsyncError} in a
2128
- * child component
2129
- *
2130
- * ```tsx
2131
- * <Await
2132
- * errorElement={<ReviewsError />}
2133
- * resolve={reviewsPromise}
2134
- * >
2135
- * <Reviews />
2136
- * </Await>
2137
- *
2138
- * function ReviewsError() {
2139
- * const error = useAsyncError();
2140
- * return <div>Error loading reviews: {error.message}</div>;
2141
- * }
2142
- * ```
2143
- *
2144
- * If you do not provide an `errorElement`, the rejected value will bubble up
2145
- * to the nearest route-level [`ErrorBoundary`](../../start/framework/route-module#errorboundary)
2146
- * and be accessible via the {@link useRouteError} hook.
2147
- */
2148
- errorElement?: React.ReactNode;
2149
- /**
2150
- * Takes a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
2151
- * returned from a [`loader`](../../start/framework/route-module#loader) to be
2152
- * resolved and rendered.
2153
- *
2154
- * ```tsx
2155
- * import { Await, useLoaderData } from "react-router";
2156
- *
2157
- * export async function loader() {
2158
- * let reviews = getReviews(); // not awaited
2159
- * let book = await getBook();
2160
- * return {
2161
- * book,
2162
- * reviews, // this is a promise
2163
- * };
2164
- * }
2165
- *
2166
- * export default function Book() {
2167
- * const {
2168
- * book,
2169
- * reviews, // this is the same promise
2170
- * } = useLoaderData();
2171
- *
2172
- * return (
2173
- * <div>
2174
- * <h1>{book.title}</h1>
2175
- * <p>{book.description}</p>
2176
- * <React.Suspense fallback={<ReviewsSkeleton />}>
2177
- * <Await
2178
- * // and is the promise we pass to Await
2179
- * resolve={reviews}
2180
- * >
2181
- * <Reviews />
2182
- * </Await>
2183
- * </React.Suspense>
2184
- * </div>
2185
- * );
2186
- * }
2187
- * ```
2188
- */
2189
- resolve: Resolve;
2190
- }
2191
- /**
2192
- * Used to render promise values with automatic error handling.
2193
- *
2194
- * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
2195
- *
2196
- * @example
2197
- * import { Await, useLoaderData } from "react-router";
2198
- *
2199
- * export async function loader() {
2200
- * // not awaited
2201
- * const reviews = getReviews();
2202
- * // awaited (blocks the transition)
2203
- * const book = await fetch("/api/book").then((res) => res.json());
2204
- * return { book, reviews };
2205
- * }
2206
- *
2207
- * function Book() {
2208
- * const { book, reviews } = useLoaderData();
2209
- * return (
2210
- * <div>
2211
- * <h1>{book.title}</h1>
2212
- * <p>{book.description}</p>
2213
- * <React.Suspense fallback={<ReviewsSkeleton />}>
2214
- * <Await
2215
- * resolve={reviews}
2216
- * errorElement={
2217
- * <div>Could not load reviews 😬</div>
2218
- * }
2219
- * children={(resolvedReviews) => (
2220
- * <Reviews items={resolvedReviews} />
2221
- * )}
2222
- * />
2223
- * </React.Suspense>
2224
- * </div>
2225
- * );
2226
- * }
2227
- *
2228
- * @public
2229
- * @category Components
2230
- * @mode framework
2231
- * @mode data
2232
- * @param props Props
2233
- * @param {AwaitProps.children} props.children n/a
2234
- * @param {AwaitProps.errorElement} props.errorElement n/a
2235
- * @param {AwaitProps.resolve} props.resolve n/a
2236
- * @returns React element for the rendered awaited value
2237
- */
2238
- declare function Await$1<Resolve>({ children, errorElement, resolve, }: AwaitProps<Resolve>): React.JSX.Element;
2239
-
2240
- declare function getRequest(): Request;
2241
- declare const redirect: typeof redirect$1;
2242
- declare const redirectDocument: typeof redirectDocument$1;
2243
- declare const replace: typeof replace$1;
2244
- declare const Await: typeof Await$1;
2245
- type RSCRouteConfigEntryBase = {
2246
- action?: ActionFunction;
2247
- clientAction?: ClientActionFunction;
2248
- clientLoader?: ClientLoaderFunction;
2249
- ErrorBoundary?: React.ComponentType<any>;
2250
- handle?: any;
2251
- headers?: HeadersFunction;
2252
- HydrateFallback?: React.ComponentType<any>;
2253
- Layout?: React.ComponentType<any>;
2254
- links?: LinksFunction;
2255
- loader?: LoaderFunction;
2256
- meta?: MetaFunction;
2257
- shouldRevalidate?: ShouldRevalidateFunction;
2258
- };
2259
- type RSCRouteConfigEntry = RSCRouteConfigEntryBase & {
2260
- id: string;
2261
- path?: string;
2262
- Component?: React.ComponentType<any>;
2263
- lazy?: () => Promise<RSCRouteConfigEntryBase & ({
2264
- default?: React.ComponentType<any>;
2265
- Component?: never;
2266
- } | {
2267
- default?: never;
2268
- Component?: React.ComponentType<any>;
2269
- })>;
2270
- } & ({
2271
- index: true;
2272
- } | {
2273
- children?: RSCRouteConfigEntry[];
2274
- });
2275
- type RSCRouteConfig = Array<RSCRouteConfigEntry>;
2276
- type RSCRouteManifest = {
2277
- clientAction?: ClientActionFunction;
2278
- clientLoader?: ClientLoaderFunction;
2279
- element?: React.ReactElement | false;
2280
- errorElement?: React.ReactElement;
2281
- handle?: any;
2282
- hasAction: boolean;
2283
- hasComponent: boolean;
2284
- hasErrorBoundary: boolean;
2285
- hasLoader: boolean;
2286
- hydrateFallbackElement?: React.ReactElement;
2287
- id: string;
2288
- index?: boolean;
2289
- links?: LinksFunction;
2290
- meta?: MetaFunction;
2291
- parentId?: string;
2292
- path?: string;
2293
- shouldRevalidate?: ShouldRevalidateFunction;
2294
- };
2295
- type RSCRouteMatch = RSCRouteManifest & {
2296
- params: Params;
2297
- pathname: string;
2298
- pathnameBase: string;
2299
- };
2300
- type RSCRenderPayload = {
2301
- type: "render";
2302
- actionData: Record<string, any> | null;
2303
- basename: string | undefined;
2304
- errors: Record<string, any> | null;
2305
- loaderData: Record<string, any>;
2306
- location: Location;
2307
- routeDiscovery: RouteDiscovery;
2308
- matches: RSCRouteMatch[];
2309
- patches?: Promise<RSCRouteManifest[]>;
2310
- nonce?: string;
2311
- formState?: unknown;
2312
- };
2313
- type RSCManifestPayload = {
2314
- type: "manifest";
2315
- patches: Promise<RSCRouteManifest[]>;
2316
- };
2317
- type RSCActionPayload = {
2318
- type: "action";
2319
- actionResult: Promise<unknown>;
2320
- rerender?: Promise<RSCRenderPayload | RSCRedirectPayload>;
2321
- };
2322
- type RSCRedirectPayload = {
2323
- type: "redirect";
2324
- status: number;
2325
- location: string;
2326
- replace: boolean;
2327
- reload: boolean;
2328
- actionResult?: Promise<unknown>;
2329
- };
2330
- type RSCPayload = RSCRenderPayload | RSCManifestPayload | RSCActionPayload | RSCRedirectPayload;
2331
- type RSCMatch = {
2332
- statusCode: number;
2333
- headers: Headers;
2334
- payload: RSCPayload;
2335
- };
2336
- type DecodeActionFunction = (formData: FormData) => Promise<() => Promise<unknown>>;
2337
- type DecodeFormStateFunction = (result: unknown, formData: FormData) => unknown;
2338
- type DecodeReplyFunction = (reply: FormData | string, options: {
2339
- temporaryReferences: unknown;
2340
- }) => Promise<unknown[]>;
2341
- type LoadServerActionFunction = (id: string) => Promise<Function>;
2342
- type RouteDiscovery = {
2343
- mode: "lazy";
2344
- manifestPath?: string | undefined;
2345
- } | {
2346
- mode: "initial";
2347
- };
2348
- /**
2349
- * Matches the given routes to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
2350
- * and returns an [RSC](https://react.dev/reference/rsc/server-components)
2351
- * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
2352
- * encoding an {@link unstable_RSCPayload} for consumption by an [RSC](https://react.dev/reference/rsc/server-components)
2353
- * enabled client router.
2354
- *
2355
- * @example
2356
- * import {
2357
- * createTemporaryReferenceSet,
2358
- * decodeAction,
2359
- * decodeReply,
2360
- * loadServerAction,
2361
- * renderToReadableStream,
2362
- * } from "@vitejs/plugin-rsc/rsc";
2363
- * import { unstable_matchRSCServerRequest as matchRSCServerRequest } from "react-router";
2364
- *
2365
- * matchRSCServerRequest({
2366
- * createTemporaryReferenceSet,
2367
- * decodeAction,
2368
- * decodeFormState,
2369
- * decodeReply,
2370
- * loadServerAction,
2371
- * request,
2372
- * routes: routes(),
2373
- * generateResponse(match) {
2374
- * return new Response(
2375
- * renderToReadableStream(match.payload),
2376
- * {
2377
- * status: match.statusCode,
2378
- * headers: match.headers,
2379
- * }
2380
- * );
2381
- * },
2382
- * });
2383
- *
2384
- * @name unstable_matchRSCServerRequest
2385
- * @public
2386
- * @category RSC
2387
- * @mode data
2388
- * @param opts Options
2389
- * @param opts.allowedActionOrigins Origin patterns that are allowed to execute actions.
2390
- * @param opts.basename The basename to use when matching the request.
2391
- * @param opts.createTemporaryReferenceSet A function that returns a temporary
2392
- * reference set for the request, used to track temporary references in the [RSC](https://react.dev/reference/rsc/server-components)
2393
- * stream.
2394
- * @param opts.decodeAction Your `react-server-dom-xyz/server`'s `decodeAction`
2395
- * function, responsible for loading a server action.
2396
- * @param opts.decodeFormState A function responsible for decoding form state for
2397
- * progressively enhanceable forms with React's [`useActionState`](https://react.dev/reference/react/useActionState)
2398
- * using your `react-server-dom-xyz/server`'s `decodeFormState`.
2399
- * @param opts.decodeReply Your `react-server-dom-xyz/server`'s `decodeReply`
2400
- * function, used to decode the server function's arguments and bind them to the
2401
- * implementation for invocation by the router.
2402
- * @param opts.generateResponse A function responsible for using your
2403
- * `renderToReadableStream` to generate a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
2404
- * encoding the {@link unstable_RSCPayload}.
2405
- * @param opts.loadServerAction Your `react-server-dom-xyz/server`'s
2406
- * `loadServerAction` function, used to load a server action by ID.
2407
- * @param opts.onError An optional error handler that will be called with any
2408
- * errors that occur during the request processing.
2409
- * @param opts.request The [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
2410
- * to match against.
2411
- * @param opts.requestContext An instance of {@link RouterContextProvider}
2412
- * that should be created per request, to be passed to [`action`](../../start/data/route-object#action)s,
2413
- * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
2414
- * @param opts.routeDiscovery The route discovery configuration, used to determine how the router should discover new routes during navigations.
2415
- * @param opts.routes Your {@link unstable_RSCRouteConfigEntry | route definitions}.
2416
- * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
2417
- * that contains the [RSC](https://react.dev/reference/rsc/server-components)
2418
- * data for hydration.
2419
- */
2420
- declare function matchRSCServerRequest({ allowedActionOrigins, createTemporaryReferenceSet, basename, decodeReply, requestContext, routeDiscovery, loadServerAction, decodeAction, decodeFormState, onError, request, routes, generateResponse, }: {
2421
- allowedActionOrigins?: string[];
2422
- createTemporaryReferenceSet: () => unknown;
2423
- basename?: string;
2424
- decodeReply?: DecodeReplyFunction;
2425
- decodeAction?: DecodeActionFunction;
2426
- decodeFormState?: DecodeFormStateFunction;
2427
- requestContext?: RouterContextProvider;
2428
- loadServerAction?: LoadServerActionFunction;
2429
- onError?: (error: unknown) => void;
2430
- request: Request;
2431
- routes: RSCRouteConfigEntry[];
2432
- routeDiscovery?: RouteDiscovery;
2433
- generateResponse: (match: RSCMatch, { onError, temporaryReferences, }: {
2434
- onError(error: unknown): string | undefined;
2435
- temporaryReferences: unknown;
2436
- }) => Response;
2437
- }): Promise<Response>;
2438
-
2439
- /**
2440
- * Apps can use this interface to "register" app-wide types for React Router via interface declaration merging and module augmentation.
2441
- * React Router should handle this for you via type generation.
2442
- *
2443
- * For more on declaration merging and module augmentation, see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation .
2444
- */
2445
- interface Register {
2446
- }
2447
- type AnyParams = Record<string, string | undefined>;
2448
- type AnyPages = Record<string, {
2449
- params: AnyParams;
2450
- }>;
2451
- type Pages = Register extends {
2452
- pages: infer Registered extends AnyPages;
2453
- } ? Registered : AnyPages;
2454
-
2455
- type Args = {
2456
- [K in keyof Pages]: ToArgs<Pages[K]["params"]>;
2457
- };
2458
- type ToArgs<Params extends Record<string, string | undefined>> = Equal<Params, {}> extends true ? [] : Partial<Params> extends Params ? [Params] | [] : [
2459
- Params
2460
- ];
2461
- /**
2462
- Returns a resolved URL path for the specified route.
2463
-
2464
- ```tsx
2465
- const h = href("/:lang?/about", { lang: "en" })
2466
- // -> `/en/about`
2467
-
2468
- <Link to={href("/products/:id", { id: "abc123" })} />
2469
- ```
2470
- */
2471
- declare function href<Path extends keyof Args>(path: Path, ...args: Args[Path]): string;
2472
-
2473
- interface CookieSignatureOptions {
2474
- /**
2475
- * An array of secrets that may be used to sign/unsign the value of a cookie.
2476
- *
2477
- * The array makes it easy to rotate secrets. New secrets should be added to
2478
- * the beginning of the array. `cookie.serialize()` will always use the first
2479
- * value in the array, but `cookie.parse()` may use any of them so that
2480
- * cookies that were signed with older secrets still work.
2481
- */
2482
- secrets?: string[];
2483
- }
2484
- type CookieOptions = ParseOptions & SerializeOptions & CookieSignatureOptions;
2485
- /**
2486
- * A HTTP cookie.
2487
- *
2488
- * A Cookie is a logical container for metadata about a HTTP cookie; its name
2489
- * and options. But it doesn't contain a value. Instead, it has `parse()` and
2490
- * `serialize()` methods that allow a single instance to be reused for
2491
- * parsing/encoding multiple different values.
2492
- *
2493
- * @see https://remix.run/utils/cookies#cookie-api
2494
- */
2495
- interface Cookie {
2496
- /**
2497
- * The name of the cookie, used in the `Cookie` and `Set-Cookie` headers.
2498
- */
2499
- readonly name: string;
2500
- /**
2501
- * True if this cookie uses one or more secrets for verification.
2502
- */
2503
- readonly isSigned: boolean;
2504
- /**
2505
- * The Date this cookie expires.
2506
- *
2507
- * Note: This is calculated at access time using `maxAge` when no `expires`
2508
- * option is provided to `createCookie()`.
2509
- */
2510
- readonly expires?: Date;
2511
- /**
2512
- * Parses a raw `Cookie` header and returns the value of this cookie or
2513
- * `null` if it's not present.
2514
- */
2515
- parse(cookieHeader: string | null, options?: ParseOptions): Promise<any>;
2516
- /**
2517
- * Serializes the given value to a string and returns the `Set-Cookie`
2518
- * header.
2519
- */
2520
- serialize(value: any, options?: SerializeOptions): Promise<string>;
2521
- }
2522
- /**
2523
- * Creates a logical container for managing a browser cookie from the server.
2524
- */
2525
- declare const createCookie: (name: string, cookieOptions?: CookieOptions) => Cookie;
2526
- type IsCookieFunction = (object: any) => object is Cookie;
2527
- /**
2528
- * Returns true if an object is a Remix cookie container.
2529
- *
2530
- * @see https://remix.run/utils/cookies#iscookie
2531
- */
2532
- declare const isCookie: IsCookieFunction;
2533
-
2534
- /**
2535
- * An object of name/value pairs to be used in the session.
2536
- */
2537
- interface SessionData {
2538
- [name: string]: any;
2539
- }
2540
- /**
2541
- * Session persists data across HTTP requests.
2542
- *
2543
- * @see https://reactrouter.com/explanation/sessions-and-cookies#sessions
2544
- */
2545
- interface Session<Data = SessionData, FlashData = Data> {
2546
- /**
2547
- * A unique identifier for this session.
2548
- *
2549
- * Note: This will be the empty string for newly created sessions and
2550
- * sessions that are not backed by a database (i.e. cookie-based sessions).
2551
- */
2552
- readonly id: string;
2553
- /**
2554
- * The raw data contained in this session.
2555
- *
2556
- * This is useful mostly for SessionStorage internally to access the raw
2557
- * session data to persist.
2558
- */
2559
- readonly data: FlashSessionData<Data, FlashData>;
2560
- /**
2561
- * Returns `true` if the session has a value for the given `name`, `false`
2562
- * otherwise.
2563
- */
2564
- has(name: (keyof Data | keyof FlashData) & string): boolean;
2565
- /**
2566
- * Returns the value for the given `name` in this session.
2567
- */
2568
- get<Key extends (keyof Data | keyof FlashData) & string>(name: Key): (Key extends keyof Data ? Data[Key] : undefined) | (Key extends keyof FlashData ? FlashData[Key] : undefined) | undefined;
2569
- /**
2570
- * Sets a value in the session for the given `name`.
2571
- */
2572
- set<Key extends keyof Data & string>(name: Key, value: Data[Key]): void;
2573
- /**
2574
- * Sets a value in the session that is only valid until the next `get()`.
2575
- * This can be useful for temporary values, like error messages.
2576
- */
2577
- flash<Key extends keyof FlashData & string>(name: Key, value: FlashData[Key]): void;
2578
- /**
2579
- * Removes a value from the session.
2580
- */
2581
- unset(name: keyof Data & string): void;
2582
- }
2583
- type FlashSessionData<Data, FlashData> = Partial<Data & {
2584
- [Key in keyof FlashData as FlashDataKey<Key & string>]: FlashData[Key];
2585
- }>;
2586
- type FlashDataKey<Key extends string> = `__flash_${Key}__`;
2587
- type CreateSessionFunction = <Data = SessionData, FlashData = Data>(initialData?: Data, id?: string) => Session<Data, FlashData>;
2588
- /**
2589
- * Creates a new Session object.
2590
- *
2591
- * Note: This function is typically not invoked directly by application code.
2592
- * Instead, use a `SessionStorage` object's `getSession` method.
2593
- */
2594
- declare const createSession: CreateSessionFunction;
2595
- type IsSessionFunction = (object: any) => object is Session;
2596
- /**
2597
- * Returns true if an object is a React Router session.
2598
- *
2599
- * @see https://reactrouter.com/api/utils/isSession
2600
- */
2601
- declare const isSession: IsSessionFunction;
2602
- /**
2603
- * SessionStorage stores session data between HTTP requests and knows how to
2604
- * parse and create cookies.
2605
- *
2606
- * A SessionStorage creates Session objects using a `Cookie` header as input.
2607
- * Then, later it generates the `Set-Cookie` header to be used in the response.
2608
- */
2609
- interface SessionStorage<Data = SessionData, FlashData = Data> {
2610
- /**
2611
- * Parses a Cookie header from a HTTP request and returns the associated
2612
- * Session. If there is no session associated with the cookie, this will
2613
- * return a new Session with no data.
2614
- */
2615
- getSession: (cookieHeader?: string | null, options?: ParseOptions) => Promise<Session<Data, FlashData>>;
2616
- /**
2617
- * Stores all data in the Session and returns the Set-Cookie header to be
2618
- * used in the HTTP response.
2619
- */
2620
- commitSession: (session: Session<Data, FlashData>, options?: SerializeOptions) => Promise<string>;
2621
- /**
2622
- * Deletes all data associated with the Session and returns the Set-Cookie
2623
- * header to be used in the HTTP response.
2624
- */
2625
- destroySession: (session: Session<Data, FlashData>, options?: SerializeOptions) => Promise<string>;
2626
- }
2627
- /**
2628
- * SessionIdStorageStrategy is designed to allow anyone to easily build their
2629
- * own SessionStorage using `createSessionStorage(strategy)`.
2630
- *
2631
- * This strategy describes a common scenario where the session id is stored in
2632
- * a cookie but the actual session data is stored elsewhere, usually in a
2633
- * database or on disk. A set of create, read, update, and delete operations
2634
- * are provided for managing the session data.
2635
- */
2636
- interface SessionIdStorageStrategy<Data = SessionData, FlashData = Data> {
2637
- /**
2638
- * The Cookie used to store the session id, or options used to automatically
2639
- * create one.
2640
- */
2641
- cookie?: Cookie | (CookieOptions & {
2642
- name?: string;
2643
- });
2644
- /**
2645
- * Creates a new record with the given data and returns the session id.
2646
- */
2647
- createData: (data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<string>;
2648
- /**
2649
- * Returns data for a given session id, or `null` if there isn't any.
2650
- */
2651
- readData: (id: string) => Promise<FlashSessionData<Data, FlashData> | null>;
2652
- /**
2653
- * Updates data for the given session id.
2654
- */
2655
- updateData: (id: string, data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<void>;
2656
- /**
2657
- * Deletes data for a given session id from the data store.
2658
- */
2659
- deleteData: (id: string) => Promise<void>;
2660
- }
2661
- /**
2662
- * Creates a SessionStorage object using a SessionIdStorageStrategy.
2663
- *
2664
- * Note: This is a low-level API that should only be used if none of the
2665
- * existing session storage options meet your requirements.
2666
- */
2667
- declare function createSessionStorage<Data = SessionData, FlashData = Data>({ cookie: cookieArg, createData, readData, updateData, deleteData, }: SessionIdStorageStrategy<Data, FlashData>): SessionStorage<Data, FlashData>;
2668
-
2669
- interface CookieSessionStorageOptions {
2670
- /**
2671
- * The Cookie used to store the session data on the client, or options used
2672
- * to automatically create one.
2673
- */
2674
- cookie?: SessionIdStorageStrategy["cookie"];
2675
- }
2676
- /**
2677
- * Creates and returns a SessionStorage object that stores all session data
2678
- * directly in the session cookie itself.
2679
- *
2680
- * This has the advantage that no database or other backend services are
2681
- * needed, and can help to simplify some load-balanced scenarios. However, it
2682
- * also has the limitation that serialized session data may not exceed the
2683
- * browser's maximum cookie size. Trade-offs!
2684
- */
2685
- declare function createCookieSessionStorage<Data = SessionData, FlashData = Data>({ cookie: cookieArg }?: CookieSessionStorageOptions): SessionStorage<Data, FlashData>;
2686
-
2687
- interface MemorySessionStorageOptions {
2688
- /**
2689
- * The Cookie used to store the session id on the client, or options used
2690
- * to automatically create one.
2691
- */
2692
- cookie?: SessionIdStorageStrategy["cookie"];
2693
- }
2694
- /**
2695
- * Creates and returns a simple in-memory SessionStorage object, mostly useful
2696
- * for testing and as a reference implementation.
2697
- *
2698
- * Note: This storage does not scale beyond a single process, so it is not
2699
- * suitable for most production scenarios.
2700
- */
2701
- declare function createMemorySessionStorage<Data = SessionData, FlashData = Data>({ cookie }?: MemorySessionStorageOptions): SessionStorage<Data, FlashData>;
2702
-
2703
- export { Await, type Cookie, type CookieOptions, type CookieSignatureOptions, type FlashSessionData, type IsCookieFunction, type IsSessionFunction, type MiddlewareFunction, type MiddlewareNextFunction, type RouterContext, RouterContextProvider, type Session, type SessionData, type SessionIdStorageStrategy, type SessionStorage, createContext, createCookie, createCookieSessionStorage, createMemorySessionStorage, createSession, createSessionStorage, createStaticHandler, data, href, isCookie, isRouteErrorResponse, isSession, matchRoutes, redirect, redirectDocument, replace, type DecodeActionFunction as unstable_DecodeActionFunction, type DecodeFormStateFunction as unstable_DecodeFormStateFunction, type DecodeReplyFunction as unstable_DecodeReplyFunction, type LoadServerActionFunction as unstable_LoadServerActionFunction, type RSCManifestPayload as unstable_RSCManifestPayload, type RSCMatch as unstable_RSCMatch, type RSCPayload as unstable_RSCPayload, type RSCRenderPayload as unstable_RSCRenderPayload, type RSCRouteConfig as unstable_RSCRouteConfig, type RSCRouteConfigEntry as unstable_RSCRouteConfigEntry, type RSCRouteManifest as unstable_RSCRouteManifest, type RSCRouteMatch as unstable_RSCRouteMatch, getRequest as unstable_getRequest, matchRSCServerRequest as unstable_matchRSCServerRequest };