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
@@ -0,0 +1,1386 @@
1
+ /**
2
+ * react-router v8.0.0-pre.0
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import { invariant, parsePath, warning } from "./router/history.js";
12
+ import { convertRouteMatchToUiMatch, decodePath, getResolveToMatches, getRoutePattern, isBrowser, isRouteErrorResponse, joinPaths, matchPath, matchRoutes, parseToInfo, resolveTo, stripBasename } from "./router/utils.js";
13
+ import { IDLE_BLOCKER } from "./router/router.js";
14
+ import { AwaitContext, DataRouterContext, DataRouterStateContext, LocationContext, NavigationContext, RSCRouterContext, RouteContext, RouteErrorContext } from "./context.js";
15
+ import { decodeRedirectErrorDigest, decodeRouteErrorResponseDigest } from "./errors.js";
16
+ import * as React$1 from "react";
17
+ //#region lib/hooks.tsx
18
+ /**
19
+ * Resolves a URL against the current {@link Location}.
20
+ *
21
+ * @example
22
+ * import { useHref } from "react-router";
23
+ *
24
+ * function SomeComponent() {
25
+ * let href = useHref("some/where");
26
+ * // "/resolved/some/where"
27
+ * }
28
+ *
29
+ * @public
30
+ * @category Hooks
31
+ * @param to The path to resolve
32
+ * @param options Options
33
+ * @param options.relative Defaults to `"route"` so routing is relative to the
34
+ * route tree.
35
+ * Set to `"path"` to make relative routing operate against path segments.
36
+ * @returns The resolved href string
37
+ */
38
+ function useHref(to, { relative } = {}) {
39
+ invariant(useInRouterContext(), `useHref() may be used only in the context of a <Router> component.`);
40
+ let { basename, navigator } = React$1.useContext(NavigationContext);
41
+ let { hash, pathname, search } = useResolvedPath(to, { relative });
42
+ let joinedPathname = pathname;
43
+ if (basename !== "/") joinedPathname = pathname === "/" ? basename : joinPaths([basename, pathname]);
44
+ return navigator.createHref({
45
+ pathname: joinedPathname,
46
+ search,
47
+ hash
48
+ });
49
+ }
50
+ /**
51
+ * Returns `true` if this component is a descendant of a {@link Router}, useful
52
+ * to ensure a component is used within a {@link Router}.
53
+ *
54
+ * @public
55
+ * @category Hooks
56
+ * @mode framework
57
+ * @mode data
58
+ * @returns Whether the component is within a {@link Router} context
59
+ */
60
+ function useInRouterContext() {
61
+ return React$1.useContext(LocationContext) != null;
62
+ }
63
+ /**
64
+ * Returns the current {@link Location}. This can be useful if you'd like to
65
+ * perform some side effect whenever it changes.
66
+ *
67
+ * @example
68
+ * import * as React from 'react'
69
+ * import { useLocation } from 'react-router'
70
+ *
71
+ * function SomeComponent() {
72
+ * let location = useLocation()
73
+ *
74
+ * React.useEffect(() => {
75
+ * // Google Analytics
76
+ * ga('send', 'pageview')
77
+ * }, [location]);
78
+ *
79
+ * return (
80
+ * // ...
81
+ * );
82
+ * }
83
+ *
84
+ * @public
85
+ * @category Hooks
86
+ * @returns The current {@link Location} object
87
+ */
88
+ function useLocation() {
89
+ invariant(useInRouterContext(), `useLocation() may be used only in the context of a <Router> component.`);
90
+ return React$1.useContext(LocationContext).location;
91
+ }
92
+ /**
93
+ * Returns the current {@link Navigation} action which describes how the router
94
+ * came to the current {@link Location}, either by a pop, push, or replace on
95
+ * the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History) stack.
96
+ *
97
+ * @public
98
+ * @category Hooks
99
+ * @returns The current {@link NavigationType} (`"POP"`, `"PUSH"`, or `"REPLACE"`)
100
+ */
101
+ function useNavigationType() {
102
+ return React$1.useContext(LocationContext).navigationType;
103
+ }
104
+ /**
105
+ * Returns a {@link PathMatch} object if the given pattern matches the current URL.
106
+ * This is useful for components that need to know "active" state, e.g.
107
+ * {@link NavLink | `<NavLink>`}.
108
+ *
109
+ * @public
110
+ * @category Hooks
111
+ * @param pattern The pattern to match against the current {@link Location}
112
+ * @returns The path match object if the pattern matches, `null` otherwise
113
+ */
114
+ function useMatch(pattern) {
115
+ invariant(useInRouterContext(), `useMatch() may be used only in the context of a <Router> component.`);
116
+ let { pathname } = useLocation();
117
+ return React$1.useMemo(() => matchPath(pattern, decodePath(pathname)), [pathname, pattern]);
118
+ }
119
+ const navigateEffectWarning = "You should call navigate() in a React.useEffect(), not when your component is first rendered.";
120
+ /**
121
+ * Returns a function that lets you navigate programmatically in the browser in
122
+ * response to user interactions or effects.
123
+ *
124
+ * It's often better to use {@link redirect} in [`action`](../../start/framework/route-module#action)/[`loader`](../../start/framework/route-module#loader)
125
+ * functions than this hook.
126
+ *
127
+ * The returned function signature is `navigate(to, options?)`/`navigate(delta)` where:
128
+ *
129
+ * * `to` can be a string path, a {@link To} object, or a number (delta)
130
+ * * `options` contains options for modifying the navigation
131
+ * * These options work in all modes (Framework, Data, and Declarative):
132
+ * * `relative`: `"route"` or `"path"` to control relative routing logic
133
+ * * `replace`: Replace the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History) stack
134
+ * * `state`: Optional [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state) to include with the new {@link Location}
135
+ * * These options only work in Framework and Data modes:
136
+ * * `flushSync`: Wrap the DOM updates in [`ReactDom.flushSync`](https://react.dev/reference/react-dom/flushSync)
137
+ * * `preventScrollReset`: Do not scroll back to the top of the page after navigation
138
+ * * `viewTransition`: Enable [`document.startViewTransition`](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for this navigation
139
+ *
140
+ * @example
141
+ * import { useNavigate } from "react-router";
142
+ *
143
+ * function SomeComponent() {
144
+ * let navigate = useNavigate();
145
+ * return (
146
+ * <button onClick={() => navigate(-1)}>
147
+ * Go Back
148
+ * </button>
149
+ * );
150
+ * }
151
+ *
152
+ * @additionalExamples
153
+ * ### Navigate to another path
154
+ *
155
+ * ```tsx
156
+ * navigate("/some/route");
157
+ * navigate("/some/route?search=param");
158
+ * ```
159
+ *
160
+ * ### Navigate with a {@link To} object
161
+ *
162
+ * All properties are optional.
163
+ *
164
+ * ```tsx
165
+ * navigate({
166
+ * pathname: "/some/route",
167
+ * search: "?search=param",
168
+ * hash: "#hash",
169
+ * state: { some: "state" },
170
+ * });
171
+ * ```
172
+ *
173
+ * If you use `state`, that will be available on the {@link Location} object on
174
+ * the next page. Access it with `useLocation().state` (see {@link useLocation}).
175
+ *
176
+ * ### Navigate back or forward in the history stack
177
+ *
178
+ * ```tsx
179
+ * // back
180
+ * // often used to close modals
181
+ * navigate(-1);
182
+ *
183
+ * // forward
184
+ * // often used in a multistep wizard workflows
185
+ * navigate(1);
186
+ * ```
187
+ *
188
+ * Be cautious with `navigate(number)`. If your application can load up to a
189
+ * route that has a button that tries to navigate forward/back, there may not be
190
+ * a [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
191
+ * entry to go back or forward to, or it can go somewhere you don't expect
192
+ * (like a different domain).
193
+ *
194
+ * Only use this if you're sure they will have an entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
195
+ * stack to navigate to.
196
+ *
197
+ * ### Replace the current entry in the history stack
198
+ *
199
+ * This will remove the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
200
+ * stack, replacing it with a new one, similar to a server side redirect.
201
+ *
202
+ * ```tsx
203
+ * navigate("/some/route", { replace: true });
204
+ * ```
205
+ *
206
+ * ### Prevent Scroll Reset
207
+ *
208
+ * [MODES: framework, data]
209
+ *
210
+ * <br/>
211
+ * <br/>
212
+ *
213
+ * To prevent {@link ScrollRestoration | `<ScrollRestoration>`} from resetting
214
+ * the scroll position, use the `preventScrollReset` option.
215
+ *
216
+ * ```tsx
217
+ * navigate("?some-tab=1", { preventScrollReset: true });
218
+ * ```
219
+ *
220
+ * For example, if you have a tab interface connected to search params in the
221
+ * middle of a page, and you don't want it to scroll to the top when a tab is
222
+ * clicked.
223
+ *
224
+ * ### Return Type Augmentation
225
+ *
226
+ * Internally, `useNavigate` uses a separate implementation when you are in
227
+ * Declarative mode versus Data/Framework mode - the primary difference being
228
+ * that the latter is able to return a stable reference that does not change
229
+ * identity across navigations. The implementation in Data/Framework mode also
230
+ * returns a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
231
+ * that resolves when the navigation is completed. This means the return type of
232
+ * `useNavigate` is `void | Promise<void>`. This is accurate, but can lead to
233
+ * some red squigglies based on the union in the return value:
234
+ *
235
+ * - If you're using `typescript-eslint`, you may see errors from
236
+ * [`@typescript-eslint/no-floating-promises`](https://typescript-eslint.io/rules/no-floating-promises)
237
+ * - In Framework/Data mode, `React.use(navigate())` will show a false-positive
238
+ * `Argument of type 'void | Promise<void>' is not assignable to parameter of
239
+ * type 'Usable<void>'` error
240
+ *
241
+ * The easiest way to work around these issues is to augment the type based on the
242
+ * router you're using:
243
+ *
244
+ * ```ts
245
+ * // If using <BrowserRouter>
246
+ * declare module "react-router" {
247
+ * interface NavigateFunction {
248
+ * (to: To, options?: NavigateOptions): void;
249
+ * (delta: number): void;
250
+ * }
251
+ * }
252
+ *
253
+ * // If using <RouterProvider> or Framework mode
254
+ * declare module "react-router" {
255
+ * interface NavigateFunction {
256
+ * (to: To, options?: NavigateOptions): Promise<void>;
257
+ * (delta: number): Promise<void>;
258
+ * }
259
+ * }
260
+ * ```
261
+ *
262
+ * @public
263
+ * @category Hooks
264
+ * @returns A navigate function for programmatic navigation
265
+ */
266
+ function useNavigate() {
267
+ let { isDataRoute } = React$1.useContext(RouteContext);
268
+ return isDataRoute ? useNavigateStable() : useNavigateUnstable();
269
+ }
270
+ function useNavigateUnstable() {
271
+ invariant(useInRouterContext(), `useNavigate() may be used only in the context of a <Router> component.`);
272
+ let dataRouterContext = React$1.useContext(DataRouterContext);
273
+ let { basename, navigator } = React$1.useContext(NavigationContext);
274
+ let { matches } = React$1.useContext(RouteContext);
275
+ let { pathname: locationPathname } = useLocation();
276
+ let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
277
+ let activeRef = React$1.useRef(false);
278
+ React$1.useLayoutEffect(() => {
279
+ activeRef.current = true;
280
+ });
281
+ return React$1.useCallback((to, options = {}) => {
282
+ warning(activeRef.current, navigateEffectWarning);
283
+ if (!activeRef.current) return;
284
+ if (typeof to === "number") {
285
+ navigator.go(to);
286
+ return;
287
+ }
288
+ let path = resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, options.relative === "path");
289
+ if (dataRouterContext == null && basename !== "/") path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
290
+ (!!options.replace ? navigator.replace : navigator.push)(path, options.state, options);
291
+ }, [
292
+ basename,
293
+ navigator,
294
+ routePathnamesJson,
295
+ locationPathname,
296
+ dataRouterContext
297
+ ]);
298
+ }
299
+ const OutletContext = React$1.createContext(null);
300
+ /**
301
+ * Returns the parent route {@link Outlet | `<Outlet context>`}.
302
+ *
303
+ * Often parent routes manage state or other values you want shared with child
304
+ * routes. You can create your own [context provider](https://react.dev/learn/passing-data-deeply-with-context)
305
+ * if you like, but this is such a common situation that it's built-into
306
+ * {@link Outlet | `<Outlet>`}.
307
+ *
308
+ * ```tsx
309
+ * // Parent route
310
+ * function Parent() {
311
+ * const [count, setCount] = React.useState(0);
312
+ * return <Outlet context={[count, setCount]} />;
313
+ * }
314
+ * ```
315
+ *
316
+ * ```tsx
317
+ * // Child route
318
+ * import { useOutletContext } from "react-router";
319
+ *
320
+ * function Child() {
321
+ * const [count, setCount] = useOutletContext();
322
+ * const increment = () => setCount((c) => c + 1);
323
+ * return <button onClick={increment}>{count}</button>;
324
+ * }
325
+ * ```
326
+ *
327
+ * If you're using TypeScript, we recommend the parent component provide a
328
+ * custom hook for accessing the context value. This makes it easier for
329
+ * consumers to get nice typings, control consumers, and know who's consuming
330
+ * the context value.
331
+ *
332
+ * Here's a more realistic example:
333
+ *
334
+ * ```tsx filename=src/routes/dashboard.tsx lines=[14,20]
335
+ * import { useState } from "react";
336
+ * import { Outlet, useOutletContext } from "react-router";
337
+ *
338
+ * import type { User } from "./types";
339
+ *
340
+ * type ContextType = { user: User | null };
341
+ *
342
+ * export default function Dashboard() {
343
+ * const [user, setUser] = useState<User | null>(null);
344
+ *
345
+ * return (
346
+ * <div>
347
+ * <h1>Dashboard</h1>
348
+ * <Outlet context={{ user } satisfies ContextType} />
349
+ * </div>
350
+ * );
351
+ * }
352
+ *
353
+ * export function useUser() {
354
+ * return useOutletContext<ContextType>();
355
+ * }
356
+ * ```
357
+ *
358
+ * ```tsx filename=src/routes/dashboard/messages.tsx lines=[1,4]
359
+ * import { useUser } from "../dashboard";
360
+ *
361
+ * export default function DashboardMessages() {
362
+ * const { user } = useUser();
363
+ * return (
364
+ * <div>
365
+ * <h2>Messages</h2>
366
+ * <p>Hello, {user.name}!</p>
367
+ * </div>
368
+ * );
369
+ * }
370
+ * ```
371
+ *
372
+ * @public
373
+ * @category Hooks
374
+ * @returns The context value passed to the parent {@link Outlet} component
375
+ */
376
+ function useOutletContext() {
377
+ return React$1.useContext(OutletContext);
378
+ }
379
+ /**
380
+ * Returns the element for the child route at this level of the route
381
+ * hierarchy. Used internally by {@link Outlet | `<Outlet>`} to render child
382
+ * routes.
383
+ *
384
+ * @public
385
+ * @category Hooks
386
+ * @param context The context to pass to the outlet
387
+ * @returns The child route element or `null` if no child routes match
388
+ */
389
+ function useOutlet(context) {
390
+ let outlet = React$1.useContext(RouteContext).outlet;
391
+ return React$1.useMemo(() => outlet && /* @__PURE__ */ React$1.createElement(OutletContext.Provider, { value: context }, outlet), [outlet, context]);
392
+ }
393
+ /**
394
+ * Returns an object of key/value-pairs of the dynamic params from the current
395
+ * URL that were matched by the routes. Child routes inherit all params from
396
+ * their parent routes.
397
+ *
398
+ * Assuming a route pattern like `/posts/:postId` is matched by `/posts/123`
399
+ * then `params.postId` will be `"123"`.
400
+ *
401
+ * @example
402
+ * import { useParams } from "react-router";
403
+ *
404
+ * function SomeComponent() {
405
+ * let params = useParams();
406
+ * params.postId;
407
+ * }
408
+ *
409
+ * @additionalExamples
410
+ * ### Basic Usage
411
+ *
412
+ * ```tsx
413
+ * import { useParams } from "react-router";
414
+ *
415
+ * // given a route like:
416
+ * <Route path="/posts/:postId" element={<Post />} />;
417
+ *
418
+ * // or a data route like:
419
+ * createBrowserRouter([
420
+ * {
421
+ * path: "/posts/:postId",
422
+ * component: Post,
423
+ * },
424
+ * ]);
425
+ *
426
+ * // or in routes.ts
427
+ * route("/posts/:postId", "routes/post.tsx");
428
+ * ```
429
+ *
430
+ * Access the params in a component:
431
+ *
432
+ * ```tsx
433
+ * import { useParams } from "react-router";
434
+ *
435
+ * export default function Post() {
436
+ * let params = useParams();
437
+ * return <h1>Post: {params.postId}</h1>;
438
+ * }
439
+ * ```
440
+ *
441
+ * ### Multiple Params
442
+ *
443
+ * Patterns can have multiple params:
444
+ *
445
+ * ```tsx
446
+ * "/posts/:postId/comments/:commentId";
447
+ * ```
448
+ *
449
+ * All will be available in the params object:
450
+ *
451
+ * ```tsx
452
+ * import { useParams } from "react-router";
453
+ *
454
+ * export default function Post() {
455
+ * let params = useParams();
456
+ * return (
457
+ * <h1>
458
+ * Post: {params.postId}, Comment: {params.commentId}
459
+ * </h1>
460
+ * );
461
+ * }
462
+ * ```
463
+ *
464
+ * ### Catchall Params
465
+ *
466
+ * Catchall params are defined with `*`:
467
+ *
468
+ * ```tsx
469
+ * "/files/*";
470
+ * ```
471
+ *
472
+ * The matched value will be available in the params object as follows:
473
+ *
474
+ * ```tsx
475
+ * import { useParams } from "react-router";
476
+ *
477
+ * export default function File() {
478
+ * let params = useParams();
479
+ * let catchall = params["*"];
480
+ * // ...
481
+ * }
482
+ * ```
483
+ *
484
+ * You can destructure the catchall param:
485
+ *
486
+ * ```tsx
487
+ * export default function File() {
488
+ * let { "*": catchall } = useParams();
489
+ * console.log(catchall);
490
+ * }
491
+ * ```
492
+ *
493
+ * @public
494
+ * @category Hooks
495
+ * @returns An object containing the dynamic route parameters
496
+ */
497
+ function useParams() {
498
+ let { matches } = React$1.useContext(RouteContext);
499
+ return matches[matches.length - 1]?.params ?? {};
500
+ }
501
+ /**
502
+ * Resolves the pathname of the given `to` value against the current
503
+ * {@link Location}. Similar to {@link useHref}, but returns a
504
+ * {@link Path} instead of a string.
505
+ *
506
+ * @example
507
+ * import { useResolvedPath } from "react-router";
508
+ *
509
+ * function SomeComponent() {
510
+ * // if the user is at /dashboard/profile
511
+ * let path = useResolvedPath("../accounts");
512
+ * path.pathname; // "/dashboard/accounts"
513
+ * path.search; // ""
514
+ * path.hash; // ""
515
+ * }
516
+ *
517
+ * @public
518
+ * @category Hooks
519
+ * @param to The path to resolve
520
+ * @param options Options
521
+ * @param options.relative Defaults to `"route"` so routing is relative to the route tree.
522
+ * Set to `"path"` to make relative routing operate against path segments.
523
+ * @returns The resolved {@link Path} object with `pathname`, `search`, and `hash`
524
+ */
525
+ function useResolvedPath(to, { relative } = {}) {
526
+ let { matches } = React$1.useContext(RouteContext);
527
+ let { pathname: locationPathname } = useLocation();
528
+ let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
529
+ return React$1.useMemo(() => resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, relative === "path"), [
530
+ to,
531
+ routePathnamesJson,
532
+ locationPathname,
533
+ relative
534
+ ]);
535
+ }
536
+ /**
537
+ * Hook version of {@link Routes | `<Routes>`} that uses objects instead of
538
+ * components. These objects have the same properties as the component props.
539
+ * The return value of `useRoutes` is either a valid React element you can use
540
+ * to render the route tree, or `null` if nothing matched.
541
+ *
542
+ * @example
543
+ * import { useRoutes } from "react-router";
544
+ *
545
+ * function App() {
546
+ * let element = useRoutes([
547
+ * {
548
+ * path: "/",
549
+ * element: <Dashboard />,
550
+ * children: [
551
+ * {
552
+ * path: "messages",
553
+ * element: <DashboardMessages />,
554
+ * },
555
+ * { path: "tasks", element: <DashboardTasks /> },
556
+ * ],
557
+ * },
558
+ * { path: "team", element: <AboutPage /> },
559
+ * ]);
560
+ *
561
+ * return element;
562
+ * }
563
+ *
564
+ * @public
565
+ * @category Hooks
566
+ * @param routes An array of {@link RouteObject}s that define the route hierarchy
567
+ * @param locationArg An optional {@link Location} object or pathname string to
568
+ * use instead of the current {@link Location}
569
+ * @returns A React element to render the matched route, or `null` if no routes matched
570
+ */
571
+ function useRoutes(routes, locationArg) {
572
+ return useRoutesImpl(routes, locationArg);
573
+ }
574
+ function useRoutesImpl(routes, locationArg, dataRouterOpts) {
575
+ invariant(useInRouterContext(), `useRoutes() may be used only in the context of a <Router> component.`);
576
+ let { navigator } = React$1.useContext(NavigationContext);
577
+ let { matches: parentMatches } = React$1.useContext(RouteContext);
578
+ let routeMatch = parentMatches[parentMatches.length - 1];
579
+ let parentParams = routeMatch ? routeMatch.params : {};
580
+ let parentPathname = routeMatch ? routeMatch.pathname : "/";
581
+ let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
582
+ let parentRoute = routeMatch && routeMatch.route;
583
+ {
584
+ let parentPath = parentRoute && parentRoute.path || "";
585
+ warningOnce(parentPathname, !parentRoute || parentPath.endsWith("*") || parentPath.endsWith("*?"), `You rendered descendant <Routes> (or called \`useRoutes()\`) at "${parentPathname}" (under <Route path="${parentPath}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.\n\nPlease change the parent <Route path="${parentPath}"> to <Route path="${parentPath === "/" ? "*" : `${parentPath}/*`}">.`);
586
+ }
587
+ let locationFromContext = useLocation();
588
+ let location;
589
+ if (locationArg) {
590
+ let parsedLocationArg = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
591
+ invariant(parentPathnameBase === "/" || parsedLocationArg.pathname?.startsWith(parentPathnameBase), `When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${parentPathnameBase}" but pathname "${parsedLocationArg.pathname}" was given in the \`location\` prop.`);
592
+ location = parsedLocationArg;
593
+ } else location = locationFromContext;
594
+ let pathname = location.pathname || "/";
595
+ let remainingPathname = pathname;
596
+ if (parentPathnameBase !== "/") {
597
+ let parentSegments = parentPathnameBase.replace(/^\//, "").split("/");
598
+ remainingPathname = "/" + pathname.replace(/^\//, "").split("/").slice(parentSegments.length).join("/");
599
+ }
600
+ let matches = dataRouterOpts && dataRouterOpts.state.matches.length ? dataRouterOpts.state.matches.map((m) => Object.assign(m, { route: dataRouterOpts.manifest[m.route.id] || m.route })) : matchRoutes(routes, { pathname: remainingPathname });
601
+ warning(parentRoute || matches != null, `No routes matched location "${location.pathname}${location.search}${location.hash}" `);
602
+ warning(matches == null || matches[matches.length - 1].route.element !== void 0 || matches[matches.length - 1].route.Component !== void 0 || matches[matches.length - 1].route.lazy !== void 0, `Matched leaf route at location "${location.pathname}${location.search}${location.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`);
603
+ let renderedMatches = _renderMatches(matches && matches.map((match) => Object.assign({}, match, {
604
+ params: Object.assign({}, parentParams, match.params),
605
+ pathname: joinPaths([parentPathnameBase, navigator.encodeLocation ? navigator.encodeLocation(match.pathname.replace(/%/g, "%25").replace(/\?/g, "%3F").replace(/#/g, "%23")).pathname : match.pathname]),
606
+ pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([parentPathnameBase, navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase.replace(/%/g, "%25").replace(/\?/g, "%3F").replace(/#/g, "%23")).pathname : match.pathnameBase])
607
+ })), parentMatches, dataRouterOpts);
608
+ if (locationArg && renderedMatches) return /* @__PURE__ */ React$1.createElement(LocationContext.Provider, { value: {
609
+ location: {
610
+ pathname: "/",
611
+ search: "",
612
+ hash: "",
613
+ state: null,
614
+ key: "default",
615
+ mask: void 0,
616
+ ...location
617
+ },
618
+ navigationType: "POP"
619
+ } }, renderedMatches);
620
+ return renderedMatches;
621
+ }
622
+ function DefaultErrorComponent() {
623
+ let error = useRouteError();
624
+ let message = isRouteErrorResponse(error) ? `${error.status} ${error.statusText}` : error instanceof Error ? error.message : JSON.stringify(error);
625
+ let stack = error instanceof Error ? error.stack : null;
626
+ let lightgrey = "rgba(200,200,200, 0.5)";
627
+ let preStyles = {
628
+ padding: "0.5rem",
629
+ backgroundColor: lightgrey
630
+ };
631
+ let codeStyles = {
632
+ padding: "2px 4px",
633
+ backgroundColor: lightgrey
634
+ };
635
+ let devInfo = null;
636
+ console.error("Error handled by React Router default ErrorBoundary:", error);
637
+ devInfo = /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement("p", null, "💿 Hey developer 👋"), /* @__PURE__ */ React$1.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /* @__PURE__ */ React$1.createElement("code", { style: codeStyles }, "ErrorBoundary"), " or", " ", /* @__PURE__ */ React$1.createElement("code", { style: codeStyles }, "errorElement"), " prop on your route."));
638
+ return /* @__PURE__ */ React$1.createElement(React$1.Fragment, null, /* @__PURE__ */ React$1.createElement("h2", null, "Unexpected Application Error!"), /* @__PURE__ */ React$1.createElement("h3", { style: { fontStyle: "italic" } }, message), stack ? /* @__PURE__ */ React$1.createElement("pre", { style: preStyles }, stack) : null, devInfo);
639
+ }
640
+ const defaultErrorElement = /* @__PURE__ */ React$1.createElement(DefaultErrorComponent, null);
641
+ var RenderErrorBoundary = class extends React$1.Component {
642
+ constructor(props) {
643
+ super(props);
644
+ this.state = {
645
+ location: props.location,
646
+ revalidation: props.revalidation,
647
+ error: props.error
648
+ };
649
+ }
650
+ static contextType = RSCRouterContext;
651
+ static getDerivedStateFromError(error) {
652
+ return { error };
653
+ }
654
+ static getDerivedStateFromProps(props, state) {
655
+ if (state.location !== props.location || state.revalidation !== "idle" && props.revalidation === "idle") return {
656
+ error: props.error,
657
+ location: props.location,
658
+ revalidation: props.revalidation
659
+ };
660
+ return {
661
+ error: props.error !== void 0 ? props.error : state.error,
662
+ location: state.location,
663
+ revalidation: props.revalidation || state.revalidation
664
+ };
665
+ }
666
+ componentDidCatch(error, errorInfo) {
667
+ if (this.props.onError) this.props.onError(error, errorInfo);
668
+ else console.error("React Router caught the following error during render", error);
669
+ }
670
+ render() {
671
+ let error = this.state.error;
672
+ if (this.context && typeof error === "object" && error && "digest" in error && typeof error.digest === "string") {
673
+ const decoded = decodeRouteErrorResponseDigest(error.digest);
674
+ if (decoded) error = decoded;
675
+ }
676
+ let result = error !== void 0 ? /* @__PURE__ */ React$1.createElement(RouteContext.Provider, { value: this.props.routeContext }, /* @__PURE__ */ React$1.createElement(RouteErrorContext.Provider, {
677
+ value: error,
678
+ children: this.props.component
679
+ })) : this.props.children;
680
+ if (this.context) return /* @__PURE__ */ React$1.createElement(RSCErrorHandler, { error }, result);
681
+ return result;
682
+ }
683
+ };
684
+ const errorRedirectHandledMap = /* @__PURE__ */ new WeakMap();
685
+ function RSCErrorHandler({ children, error }) {
686
+ let { basename } = React$1.useContext(NavigationContext);
687
+ if (typeof error === "object" && error && "digest" in error && typeof error.digest === "string") {
688
+ let redirect = decodeRedirectErrorDigest(error.digest);
689
+ if (redirect) {
690
+ let existingRedirect = errorRedirectHandledMap.get(error);
691
+ if (existingRedirect) throw existingRedirect;
692
+ let parsed = parseToInfo(redirect.location, basename);
693
+ if (isBrowser && !errorRedirectHandledMap.get(error)) if (parsed.isExternal || redirect.reloadDocument) window.location.href = parsed.absoluteURL || parsed.to;
694
+ else {
695
+ const redirectPromise = Promise.resolve().then(() => window.__reactRouterDataRouter.navigate(parsed.to, { replace: redirect.replace }));
696
+ errorRedirectHandledMap.set(error, redirectPromise);
697
+ throw redirectPromise;
698
+ }
699
+ return /* @__PURE__ */ React$1.createElement("meta", {
700
+ httpEquiv: "refresh",
701
+ content: `0;url=${parsed.absoluteURL || parsed.to}`
702
+ });
703
+ }
704
+ }
705
+ return children;
706
+ }
707
+ function RenderedRoute({ routeContext, match, children }) {
708
+ let dataRouterContext = React$1.useContext(DataRouterContext);
709
+ if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
710
+ return /* @__PURE__ */ React$1.createElement(RouteContext.Provider, { value: routeContext }, children);
711
+ }
712
+ function _renderMatches(matches, parentMatches = [], dataRouterOpts) {
713
+ let dataRouterState = dataRouterOpts?.state;
714
+ if (matches == null) {
715
+ if (!dataRouterState) return null;
716
+ if (dataRouterState.errors) matches = dataRouterState.matches;
717
+ else if (parentMatches.length === 0 && !dataRouterState.initialized && dataRouterState.matches.length > 0) matches = dataRouterState.matches;
718
+ else return null;
719
+ }
720
+ let renderedMatches = matches;
721
+ let errors = dataRouterState?.errors;
722
+ if (errors != null) {
723
+ let errorIndex = renderedMatches.findIndex((m) => m.route.id && errors?.[m.route.id] !== void 0);
724
+ invariant(errorIndex >= 0, `Could not find a matching route for errors on route IDs: ${Object.keys(errors).join(",")}`);
725
+ renderedMatches = renderedMatches.slice(0, Math.min(renderedMatches.length, errorIndex + 1));
726
+ }
727
+ let renderFallback = false;
728
+ let fallbackIndex = -1;
729
+ if (dataRouterOpts && dataRouterState) {
730
+ renderFallback = dataRouterState.renderFallback;
731
+ for (let i = 0; i < renderedMatches.length; i++) {
732
+ let match = renderedMatches[i];
733
+ if (match.route.HydrateFallback || match.route.hydrateFallbackElement) fallbackIndex = i;
734
+ if (match.route.id) {
735
+ let { loaderData, errors } = dataRouterState;
736
+ let needsToRunLoader = match.route.loader && !loaderData.hasOwnProperty(match.route.id) && (!errors || errors[match.route.id] === void 0);
737
+ if (match.route.lazy || needsToRunLoader) {
738
+ if (dataRouterOpts.isStatic) renderFallback = true;
739
+ if (fallbackIndex >= 0) renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
740
+ else renderedMatches = [renderedMatches[0]];
741
+ break;
742
+ }
743
+ }
744
+ }
745
+ }
746
+ let onErrorHandler = dataRouterOpts?.onError;
747
+ let onError = dataRouterState && onErrorHandler ? (error, errorInfo) => {
748
+ onErrorHandler(error, {
749
+ location: dataRouterState.location,
750
+ params: dataRouterState.matches?.[0]?.params ?? {},
751
+ pattern: getRoutePattern(dataRouterState.matches),
752
+ errorInfo
753
+ });
754
+ } : void 0;
755
+ return renderedMatches.reduceRight((outlet, match, index) => {
756
+ let error;
757
+ let shouldRenderHydrateFallback = false;
758
+ let errorElement = null;
759
+ let hydrateFallbackElement = null;
760
+ if (dataRouterState) {
761
+ error = errors && match.route.id ? errors[match.route.id] : void 0;
762
+ errorElement = match.route.errorElement || defaultErrorElement;
763
+ if (renderFallback) {
764
+ if (fallbackIndex < 0 && index === 0) {
765
+ warningOnce("route-fallback", false, "No `HydrateFallback` element provided to render during initial hydration");
766
+ shouldRenderHydrateFallback = true;
767
+ hydrateFallbackElement = null;
768
+ } else if (fallbackIndex === index) {
769
+ shouldRenderHydrateFallback = true;
770
+ hydrateFallbackElement = match.route.hydrateFallbackElement || null;
771
+ }
772
+ }
773
+ }
774
+ let matches = parentMatches.concat(renderedMatches.slice(0, index + 1));
775
+ let getChildren = () => {
776
+ let children;
777
+ if (error) children = errorElement;
778
+ else if (shouldRenderHydrateFallback) children = hydrateFallbackElement;
779
+ else if (match.route.Component) children = /* @__PURE__ */ React$1.createElement(match.route.Component, null);
780
+ else if (match.route.element) children = match.route.element;
781
+ else children = outlet;
782
+ return /* @__PURE__ */ React$1.createElement(RenderedRoute, {
783
+ match,
784
+ routeContext: {
785
+ outlet,
786
+ matches,
787
+ isDataRoute: dataRouterState != null
788
+ },
789
+ children
790
+ });
791
+ };
792
+ return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? /* @__PURE__ */ React$1.createElement(RenderErrorBoundary, {
793
+ location: dataRouterState.location,
794
+ revalidation: dataRouterState.revalidation,
795
+ component: errorElement,
796
+ error,
797
+ children: getChildren(),
798
+ routeContext: {
799
+ outlet: null,
800
+ matches,
801
+ isDataRoute: true
802
+ },
803
+ onError
804
+ }) : getChildren();
805
+ }, null);
806
+ }
807
+ function getDataRouterConsoleError(hookName) {
808
+ return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
809
+ }
810
+ function useDataRouterContext(hookName) {
811
+ let ctx = React$1.useContext(DataRouterContext);
812
+ invariant(ctx, getDataRouterConsoleError(hookName));
813
+ return ctx;
814
+ }
815
+ function useDataRouterState(hookName) {
816
+ let state = React$1.useContext(DataRouterStateContext);
817
+ invariant(state, getDataRouterConsoleError(hookName));
818
+ return state;
819
+ }
820
+ function useRouteContext(hookName) {
821
+ let route = React$1.useContext(RouteContext);
822
+ invariant(route, getDataRouterConsoleError(hookName));
823
+ return route;
824
+ }
825
+ function useCurrentRouteId(hookName) {
826
+ let route = useRouteContext(hookName);
827
+ let thisRoute = route.matches[route.matches.length - 1];
828
+ invariant(thisRoute.route.id, `${hookName} can only be used on routes that contain a unique "id"`);
829
+ return thisRoute.route.id;
830
+ }
831
+ /**
832
+ * Returns the ID for the nearest contextual route
833
+ *
834
+ * @category Hooks
835
+ * @returns The ID of the nearest contextual route
836
+ */
837
+ function useRouteId() {
838
+ return useCurrentRouteId("useRouteId");
839
+ }
840
+ /**
841
+ * Returns the current {@link Navigation}, defaulting to an "idle" navigation
842
+ * when no navigation is in progress. You can use this to render pending UI
843
+ * (like a global spinner) or read [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
844
+ * from a form navigation.
845
+ *
846
+ * @example
847
+ * import { useNavigation } from "react-router";
848
+ *
849
+ * function SomeComponent() {
850
+ * let navigation = useNavigation();
851
+ * navigation.state;
852
+ * navigation.formData;
853
+ * // etc.
854
+ * }
855
+ *
856
+ * @public
857
+ * @category Hooks
858
+ * @mode framework
859
+ * @mode data
860
+ * @returns The current {@link Navigation} object
861
+ */
862
+ function useNavigation() {
863
+ let state = useDataRouterState("useNavigation");
864
+ return React$1.useMemo(() => {
865
+ let { matches, historyAction, ...rest } = state.navigation;
866
+ return rest;
867
+ }, [state.navigation]);
868
+ }
869
+ /**
870
+ * Revalidate the data on the page for reasons outside of normal data mutations
871
+ * like [`Window` focus](https://developer.mozilla.org/en-US/docs/Web/API/Window/focus_event)
872
+ * or polling on an interval.
873
+ *
874
+ * Note that page data is already revalidated automatically after actions.
875
+ * If you find yourself using this for normal CRUD operations on your data in
876
+ * response to user interactions, you're probably not taking advantage of the
877
+ * other APIs like {@link useFetcher}, {@link Form}, {@link useSubmit} that do
878
+ * this automatically.
879
+ *
880
+ * @example
881
+ * import { useRevalidator } from "react-router";
882
+ *
883
+ * function WindowFocusRevalidator() {
884
+ * const revalidator = useRevalidator();
885
+ *
886
+ * useFakeWindowFocus(() => {
887
+ * revalidator.revalidate();
888
+ * });
889
+ *
890
+ * return (
891
+ * <div hidden={revalidator.state === "idle"}>
892
+ * Revalidating...
893
+ * </div>
894
+ * );
895
+ * }
896
+ *
897
+ * @public
898
+ * @category Hooks
899
+ * @mode framework
900
+ * @mode data
901
+ * @returns An object with a `revalidate` function and the current revalidation
902
+ * `state`
903
+ */
904
+ function useRevalidator() {
905
+ let dataRouterContext = useDataRouterContext("useRevalidator");
906
+ let state = useDataRouterState("useRevalidator");
907
+ let revalidate = React$1.useCallback(async () => {
908
+ await dataRouterContext.router.revalidate();
909
+ }, [dataRouterContext.router]);
910
+ return React$1.useMemo(() => ({
911
+ revalidate,
912
+ state: state.revalidation
913
+ }), [revalidate, state.revalidation]);
914
+ }
915
+ /**
916
+ * Returns the active route matches, useful for accessing `loaderData` for
917
+ * parent/child routes or the route [`handle`](../../start/framework/route-module#handle)
918
+ * property
919
+ *
920
+ * @public
921
+ * @category Hooks
922
+ * @mode framework
923
+ * @mode data
924
+ * @returns An array of {@link UIMatch | UI matches} for the current route hierarchy
925
+ */
926
+ function useMatches() {
927
+ let { matches, loaderData } = useDataRouterState("useMatches");
928
+ return React$1.useMemo(() => matches.map((m) => convertRouteMatchToUiMatch(m, loaderData)), [matches, loaderData]);
929
+ }
930
+ /**
931
+ * Returns the data from the closest route
932
+ * [`loader`](../../start/framework/route-module#loader) or
933
+ * [`clientLoader`](../../start/framework/route-module#clientloader).
934
+ *
935
+ * @example
936
+ * import { useLoaderData } from "react-router";
937
+ *
938
+ * export async function loader() {
939
+ * return await fakeDb.invoices.findAll();
940
+ * }
941
+ *
942
+ * export default function Invoices() {
943
+ * let invoices = useLoaderData<typeof loader>();
944
+ * // ...
945
+ * }
946
+ *
947
+ * @public
948
+ * @category Hooks
949
+ * @mode framework
950
+ * @mode data
951
+ * @returns The data returned from the route's [`loader`](../../start/framework/route-module#loader) or [`clientLoader`](../../start/framework/route-module#clientloader) function
952
+ */
953
+ function useLoaderData() {
954
+ let state = useDataRouterState("useLoaderData");
955
+ let routeId = useCurrentRouteId("useLoaderData");
956
+ return state.loaderData[routeId];
957
+ }
958
+ /**
959
+ * Returns the [`loader`](../../start/framework/route-module#loader) data for a
960
+ * given route by route ID.
961
+ *
962
+ * Route IDs are created automatically. They are simply the path of the route file
963
+ * relative to the app folder without the extension.
964
+ *
965
+ * | Route Filename | Route ID |
966
+ * | ---------------------------- | ---------------------- |
967
+ * | `app/root.tsx` | `"root"` |
968
+ * | `app/routes/teams.tsx` | `"routes/teams"` |
969
+ * | `app/whatever/teams.$id.tsx` | `"whatever/teams.$id"` |
970
+ *
971
+ * @example
972
+ * import { useRouteLoaderData } from "react-router";
973
+ *
974
+ * function SomeComponent() {
975
+ * const { user } = useRouteLoaderData("root");
976
+ * }
977
+ *
978
+ * // You can also specify your own route ID's manually in your routes.ts file:
979
+ * route("/", "containers/app.tsx", { id: "app" })
980
+ * useRouteLoaderData("app");
981
+ *
982
+ * @public
983
+ * @category Hooks
984
+ * @mode framework
985
+ * @mode data
986
+ * @param routeId The ID of the route to return loader data from
987
+ * @returns The data returned from the specified route's [`loader`](../../start/framework/route-module#loader)
988
+ * function, or `undefined` if not found
989
+ */
990
+ function useRouteLoaderData(routeId) {
991
+ return useDataRouterState("useRouteLoaderData").loaderData[routeId];
992
+ }
993
+ /**
994
+ * Returns the [`action`](../../start/framework/route-module#action) data from
995
+ * the most recent `POST` navigation form submission or `undefined` if there
996
+ * hasn't been one.
997
+ *
998
+ * @example
999
+ * import { Form, useActionData } from "react-router";
1000
+ *
1001
+ * export async function action({ request }) {
1002
+ * const body = await request.formData();
1003
+ * const name = body.get("visitorsName");
1004
+ * return { message: `Hello, ${name}` };
1005
+ * }
1006
+ *
1007
+ * export default function Invoices() {
1008
+ * const data = useActionData();
1009
+ * return (
1010
+ * <Form method="post">
1011
+ * <input type="text" name="visitorsName" />
1012
+ * {data ? data.message : "Waiting..."}
1013
+ * </Form>
1014
+ * );
1015
+ * }
1016
+ *
1017
+ * @public
1018
+ * @category Hooks
1019
+ * @mode framework
1020
+ * @mode data
1021
+ * @returns The data returned from the route's [`action`](../../start/framework/route-module#action)
1022
+ * function, or `undefined` if no [`action`](../../start/framework/route-module#action)
1023
+ * has been called
1024
+ */
1025
+ function useActionData() {
1026
+ let state = useDataRouterState("useActionData");
1027
+ let routeId = useCurrentRouteId("useLoaderData");
1028
+ return state.actionData ? state.actionData[routeId] : void 0;
1029
+ }
1030
+ /**
1031
+ * Accesses the error thrown during an
1032
+ * [`action`](../../start/framework/route-module#action),
1033
+ * [`loader`](../../start/framework/route-module#loader),
1034
+ * or component render to be used in a route module
1035
+ * [`ErrorBoundary`](../../start/framework/route-module#errorboundary).
1036
+ *
1037
+ * @example
1038
+ * export function ErrorBoundary() {
1039
+ * const error = useRouteError();
1040
+ * return <div>{error.message}</div>;
1041
+ * }
1042
+ *
1043
+ * @public
1044
+ * @category Hooks
1045
+ * @mode framework
1046
+ * @mode data
1047
+ * @returns The error that was thrown during route [loading](../../start/framework/route-module#loader),
1048
+ * [`action`](../../start/framework/route-module#action) execution, or rendering
1049
+ */
1050
+ function useRouteError() {
1051
+ let error = React$1.useContext(RouteErrorContext);
1052
+ let state = useDataRouterState("useRouteError");
1053
+ let routeId = useCurrentRouteId("useRouteError");
1054
+ if (error !== void 0) return error;
1055
+ return state.errors?.[routeId];
1056
+ }
1057
+ /**
1058
+ * Returns the resolved promise value from the closest {@link Await | `<Await>`}.
1059
+ *
1060
+ * @example
1061
+ * function SomeDescendant() {
1062
+ * const value = useAsyncValue();
1063
+ * // ...
1064
+ * }
1065
+ *
1066
+ * // somewhere in your app
1067
+ * <Await resolve={somePromise}>
1068
+ * <SomeDescendant />
1069
+ * </Await>;
1070
+ *
1071
+ * @public
1072
+ * @category Hooks
1073
+ * @mode framework
1074
+ * @mode data
1075
+ * @returns The resolved value from the nearest {@link Await} component
1076
+ */
1077
+ function useAsyncValue() {
1078
+ return React$1.useContext(AwaitContext)?._data;
1079
+ }
1080
+ /**
1081
+ * Returns the rejection value from the closest {@link Await | `<Await>`}.
1082
+ *
1083
+ * @example
1084
+ * import { Await, useAsyncError } from "react-router";
1085
+ *
1086
+ * function ErrorElement() {
1087
+ * const error = useAsyncError();
1088
+ * return (
1089
+ * <p>Uh Oh, something went wrong! {error.message}</p>
1090
+ * );
1091
+ * }
1092
+ *
1093
+ * // somewhere in your app
1094
+ * <Await
1095
+ * resolve={promiseThatRejects}
1096
+ * errorElement={<ErrorElement />}
1097
+ * />;
1098
+ *
1099
+ * @public
1100
+ * @category Hooks
1101
+ * @mode framework
1102
+ * @mode data
1103
+ * @returns The error that was thrown in the nearest {@link Await} component
1104
+ */
1105
+ function useAsyncError() {
1106
+ return React$1.useContext(AwaitContext)?._error;
1107
+ }
1108
+ let blockerId = 0;
1109
+ /**
1110
+ * Allow the application to block navigations within the SPA and present the
1111
+ * user a confirmation dialog to confirm the navigation. Mostly used to avoid
1112
+ * using half-filled form data. This does not handle hard-reloads or
1113
+ * cross-origin navigations.
1114
+ *
1115
+ * The {@link Blocker} object returned by the hook has the following properties:
1116
+ *
1117
+ * - **`state`**
1118
+ * - `unblocked` - the blocker is idle and has not prevented any navigation
1119
+ * - `blocked` - the blocker has prevented a navigation
1120
+ * - `proceeding` - the blocker is proceeding through from a blocked navigation
1121
+ * - **`location`**
1122
+ * - When in a `blocked` state, this represents the {@link Location} to which
1123
+ * we blocked a navigation. When in a `proceeding` state, this is the
1124
+ * location being navigated to after a `blocker.proceed()` call.
1125
+ * - **`proceed()`**
1126
+ * - When in a `blocked` state, you may call `blocker.proceed()` to proceed to
1127
+ * the blocked location.
1128
+ * - **`reset()`**
1129
+ * - When in a `blocked` state, you may call `blocker.reset()` to return the
1130
+ * blocker to an `unblocked` state and leave the user at the current
1131
+ * location.
1132
+ *
1133
+ * @example
1134
+ * // Boolean version
1135
+ * let blocker = useBlocker(value !== "");
1136
+ *
1137
+ * // Function version
1138
+ * let blocker = useBlocker(
1139
+ * ({ currentLocation, nextLocation, historyAction }) =>
1140
+ * value !== "" &&
1141
+ * currentLocation.pathname !== nextLocation.pathname
1142
+ * );
1143
+ *
1144
+ * @additionalExamples
1145
+ * ```tsx
1146
+ * import { useCallback, useState } from "react";
1147
+ * import { BlockerFunction, useBlocker } from "react-router";
1148
+ *
1149
+ * export function ImportantForm() {
1150
+ * const [value, setValue] = useState("");
1151
+ *
1152
+ * const shouldBlock = useCallback<BlockerFunction>(
1153
+ * () => value !== "",
1154
+ * [value]
1155
+ * );
1156
+ * const blocker = useBlocker(shouldBlock);
1157
+ *
1158
+ * return (
1159
+ * <form
1160
+ * onSubmit={(e) => {
1161
+ * e.preventDefault();
1162
+ * setValue("");
1163
+ * if (blocker.state === "blocked") {
1164
+ * blocker.proceed();
1165
+ * }
1166
+ * }}
1167
+ * >
1168
+ * <input
1169
+ * name="data"
1170
+ * value={value}
1171
+ * onChange={(e) => setValue(e.target.value)}
1172
+ * />
1173
+ *
1174
+ * <button type="submit">Save</button>
1175
+ *
1176
+ * {blocker.state === "blocked" ? (
1177
+ * <>
1178
+ * <p style={{ color: "red" }}>
1179
+ * Blocked the last navigation to
1180
+ * </p>
1181
+ * <button
1182
+ * type="button"
1183
+ * onClick={() => blocker.proceed()}
1184
+ * >
1185
+ * Let me through
1186
+ * </button>
1187
+ * <button
1188
+ * type="button"
1189
+ * onClick={() => blocker.reset()}
1190
+ * >
1191
+ * Keep me here
1192
+ * </button>
1193
+ * </>
1194
+ * ) : blocker.state === "proceeding" ? (
1195
+ * <p style={{ color: "orange" }}>
1196
+ * Proceeding through blocked navigation
1197
+ * </p>
1198
+ * ) : (
1199
+ * <p style={{ color: "green" }}>
1200
+ * Blocker is currently unblocked
1201
+ * </p>
1202
+ * )}
1203
+ * </form>
1204
+ * );
1205
+ * }
1206
+ * ```
1207
+ *
1208
+ * @public
1209
+ * @category Hooks
1210
+ * @mode framework
1211
+ * @mode data
1212
+ * @param shouldBlock Either a boolean or a function returning a boolean which
1213
+ * indicates whether the navigation should be blocked. The function format
1214
+ * receives a single object parameter containing the `currentLocation`,
1215
+ * `nextLocation`, and `historyAction` of the potential navigation.
1216
+ * @returns A {@link Blocker} object with state and reset functionality
1217
+ */
1218
+ function useBlocker(shouldBlock) {
1219
+ let { router, basename } = useDataRouterContext("useBlocker");
1220
+ let state = useDataRouterState("useBlocker");
1221
+ let [blockerKey, setBlockerKey] = React$1.useState("");
1222
+ let blockerFunction = React$1.useCallback((arg) => {
1223
+ if (typeof shouldBlock !== "function") return !!shouldBlock;
1224
+ if (basename === "/") return shouldBlock(arg);
1225
+ let { currentLocation, nextLocation, historyAction } = arg;
1226
+ return shouldBlock({
1227
+ currentLocation: {
1228
+ ...currentLocation,
1229
+ pathname: stripBasename(currentLocation.pathname, basename) || currentLocation.pathname
1230
+ },
1231
+ nextLocation: {
1232
+ ...nextLocation,
1233
+ pathname: stripBasename(nextLocation.pathname, basename) || nextLocation.pathname
1234
+ },
1235
+ historyAction
1236
+ });
1237
+ }, [basename, shouldBlock]);
1238
+ React$1.useEffect(() => {
1239
+ let key = String(++blockerId);
1240
+ setBlockerKey(key);
1241
+ return () => router.deleteBlocker(key);
1242
+ }, [router]);
1243
+ React$1.useEffect(() => {
1244
+ if (blockerKey !== "") router.getBlocker(blockerKey, blockerFunction);
1245
+ }, [
1246
+ router,
1247
+ blockerKey,
1248
+ blockerFunction
1249
+ ]);
1250
+ return blockerKey && state.blockers.has(blockerKey) ? state.blockers.get(blockerKey) : IDLE_BLOCKER;
1251
+ }
1252
+ function useNavigateStable() {
1253
+ let { router } = useDataRouterContext("useNavigate");
1254
+ let id = useCurrentRouteId("useNavigate");
1255
+ let activeRef = React$1.useRef(false);
1256
+ React$1.useLayoutEffect(() => {
1257
+ activeRef.current = true;
1258
+ });
1259
+ return React$1.useCallback(async (to, options = {}) => {
1260
+ warning(activeRef.current, navigateEffectWarning);
1261
+ if (!activeRef.current) return;
1262
+ if (typeof to === "number") await router.navigate(to);
1263
+ else await router.navigate(to, {
1264
+ fromRouteId: id,
1265
+ ...options
1266
+ });
1267
+ }, [router, id]);
1268
+ }
1269
+ const alreadyWarned = {};
1270
+ function warningOnce(key, cond, message) {
1271
+ if (!cond && !alreadyWarned[key]) {
1272
+ alreadyWarned[key] = true;
1273
+ warning(false, message);
1274
+ }
1275
+ }
1276
+ function useRoute(...args) {
1277
+ const currentRouteId = useCurrentRouteId("useRoute");
1278
+ const id = args[0] ?? currentRouteId;
1279
+ const state = useDataRouterState("useRoute");
1280
+ const route = state.matches.find(({ route }) => route.id === id);
1281
+ if (route === void 0) return void 0;
1282
+ return {
1283
+ handle: route.route.handle,
1284
+ loaderData: state.loaderData[id],
1285
+ actionData: state.actionData?.[id]
1286
+ };
1287
+ }
1288
+ function toRouterStateMatch(match) {
1289
+ return {
1290
+ id: match.route.id,
1291
+ pathname: match.pathname,
1292
+ params: match.params,
1293
+ handle: match.route.handle
1294
+ };
1295
+ }
1296
+ /**
1297
+ * A unified hook for reading router state: current (`active`) and in-flight
1298
+ * (`pending`) locations, search params, params, matches, and navigation type.
1299
+ *
1300
+ * This hook consolidates the information you used to get from {@link useLocation},
1301
+ * {@link useSearchParams}, {@link useParams}, {@link useMatches}, {@link useNavigation},
1302
+ * and {@link useNavigationType} into a single hook.
1303
+ *
1304
+ *
1305
+ * @example
1306
+ * import { unstable_useRouterState as useRouterState } from "react-router";
1307
+ *
1308
+ * let { active, pending } = unstable_useRouterState();
1309
+ *
1310
+ * // Active is always populated with the current location
1311
+ * active.location; // replaces `useLocation()`
1312
+ * active.searchParams; // replaces `useSearchParams()[0]`
1313
+ * active.params; // replaces `useParams()`
1314
+ * active.matches; // replaces `useMatches()`
1315
+ * active.type; // replaces `useNavigationType()`
1316
+ *
1317
+ * // Pending is only populated during a navigation
1318
+ * pending.location; // replaces `useNavigation().location`
1319
+ * pending.searchParams; // equivalent to `new URLSearchParams(useNavigation().search)`
1320
+ * pending.params; // Not directly accessible today
1321
+ * pending.matches; // Not directly accessible today
1322
+ * pending.type; // Not directly accessible today
1323
+ * pending.state; // replaces `useNavigation().state`
1324
+ * pending.formMethod; // replaces useNavigation().formMethod
1325
+ * pending.formAction; // replaces useNavigation().formAction
1326
+ * pending.formEncType; // replaces useNavigation().formEncType
1327
+ * pending.formData; // replaces useNavigation().formData
1328
+ * pending.json; // replaces useNavigation().json
1329
+ * pending.text; // replaces useNavigation().text
1330
+ *
1331
+ * @name unstable_useRouterState
1332
+ * @public
1333
+ * @category Hooks
1334
+ * @mode framework
1335
+ * @mode data
1336
+ * @returns The current router state with `active` and `pending` variants
1337
+ */
1338
+ function useRouterState() {
1339
+ let { location, historyAction: type, matches, navigation } = useDataRouterState("unstable_useRouterState");
1340
+ let active = React$1.useMemo(() => ({
1341
+ type,
1342
+ location,
1343
+ searchParams: new URLSearchParams(location.search),
1344
+ params: matches[matches.length - 1]?.params ?? {},
1345
+ matches: matches.map((m) => toRouterStateMatch(m))
1346
+ }), [
1347
+ location,
1348
+ matches,
1349
+ type
1350
+ ]);
1351
+ let pending = React$1.useMemo(() => {
1352
+ if (navigation.state === "idle") return null;
1353
+ let shared = {
1354
+ type: navigation.historyAction,
1355
+ location: navigation.location,
1356
+ searchParams: new URLSearchParams(navigation.location.search),
1357
+ params: navigation.matches[navigation.matches.length - 1]?.params ?? {},
1358
+ matches: navigation.matches.map((m) => toRouterStateMatch(m))
1359
+ };
1360
+ return navigation.state === "loading" ? {
1361
+ ...shared,
1362
+ state: "loading",
1363
+ formMethod: navigation.formMethod,
1364
+ formAction: navigation.formAction,
1365
+ formEncType: navigation.formEncType,
1366
+ formData: navigation.formData,
1367
+ json: navigation.json,
1368
+ text: navigation.text
1369
+ } : {
1370
+ ...shared,
1371
+ state: "submitting",
1372
+ formMethod: navigation.formMethod,
1373
+ formAction: navigation.formAction,
1374
+ formEncType: navigation.formEncType,
1375
+ formData: navigation.formData,
1376
+ json: navigation.json,
1377
+ text: navigation.text
1378
+ };
1379
+ }, [navigation]);
1380
+ return React$1.useMemo(() => ({
1381
+ active,
1382
+ pending
1383
+ }), [active, pending]);
1384
+ }
1385
+ //#endregion
1386
+ export { _renderMatches, useActionData, useAsyncError, useAsyncValue, useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRoute, useRouteError, useRouteId, useRouteLoaderData, useRouterState, useRoutes, useRoutesImpl };