react-router 7.18.0 → 8.0.0-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/dist/development/dom-export.d.ts +6 -172
  2. package/dist/development/dom-export.js +12 -1009
  3. package/dist/development/index-react-server-client.d.ts +7 -4
  4. package/dist/development/index-react-server-client.js +8 -52
  5. package/dist/development/index-react-server.d.ts +1650 -1641
  6. package/dist/development/index-react-server.js +2882 -3664
  7. package/dist/development/index.d.ts +42 -1476
  8. package/dist/development/index.js +36 -2553
  9. package/dist/development/lib/actions.js +50 -0
  10. package/dist/development/lib/components.d.ts +1030 -0
  11. package/dist/development/lib/components.js +841 -0
  12. package/dist/development/lib/context.d.ts +83 -0
  13. package/dist/development/lib/context.js +41 -0
  14. package/dist/development/lib/dom/dom.d.ts +119 -0
  15. package/dist/development/lib/dom/dom.js +143 -0
  16. package/dist/development/lib/dom/lib.d.ts +2053 -0
  17. package/dist/development/lib/dom/lib.js +1271 -0
  18. package/dist/development/lib/dom/server.d.ts +138 -0
  19. package/dist/development/lib/dom/server.js +301 -0
  20. package/dist/development/lib/dom/ssr/components.d.ts +198 -0
  21. package/dist/development/lib/dom/ssr/components.js +589 -0
  22. package/dist/development/lib/dom/ssr/data.js +29 -0
  23. package/dist/development/lib/dom/ssr/entry.d.ts +60 -0
  24. package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  25. package/dist/development/lib/dom/ssr/errorBoundaries.js +87 -0
  26. package/dist/development/lib/dom/ssr/fallback.js +33 -0
  27. package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
  28. package/dist/development/lib/dom/ssr/fog-of-war.js +180 -0
  29. package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
  30. package/dist/development/lib/dom/ssr/hydration.js +29 -0
  31. package/dist/development/lib/dom/ssr/invariant.js +16 -0
  32. package/dist/development/lib/dom/ssr/links.js +170 -0
  33. package/dist/development/lib/dom/ssr/markup.js +24 -0
  34. package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
  35. package/dist/development/lib/dom/ssr/routeModules.js +31 -0
  36. package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +62 -0
  37. package/dist/development/lib/dom/ssr/routes-test-stub.js +108 -0
  38. package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
  39. package/dist/development/lib/dom/ssr/routes.js +303 -0
  40. package/dist/development/lib/dom/ssr/server.d.ts +48 -0
  41. package/dist/development/lib/dom/ssr/server.js +69 -0
  42. package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
  43. package/dist/development/lib/dom/ssr/single-fetch.js +345 -0
  44. package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
  45. package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
  46. package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
  47. package/dist/development/lib/dom-export/hydrated-router.js +150 -0
  48. package/dist/development/lib/errors.js +29 -0
  49. package/dist/development/lib/hooks.d.ts +947 -0
  50. package/dist/development/lib/hooks.js +1388 -0
  51. package/dist/development/lib/href.d.ts +20 -0
  52. package/dist/development/lib/href.js +50 -0
  53. package/dist/development/lib/router/history.d.ts +258 -0
  54. package/dist/development/lib/router/history.js +372 -0
  55. package/dist/development/lib/router/instrumentation.d.ts +86 -0
  56. package/dist/development/lib/router/instrumentation.js +213 -0
  57. package/dist/development/lib/router/links.d.ts +114 -0
  58. package/dist/development/lib/router/router.d.ts +663 -0
  59. package/dist/development/lib/router/router.js +2988 -0
  60. package/dist/development/lib/router/url.js +18 -0
  61. package/dist/development/lib/router/utils.d.ts +948 -0
  62. package/dist/development/lib/router/utils.js +810 -0
  63. package/dist/development/lib/rsc/browser.d.ts +137 -0
  64. package/dist/development/lib/rsc/browser.js +603 -0
  65. package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
  66. package/dist/development/lib/rsc/errorBoundaries.js +90 -0
  67. package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
  68. package/dist/development/lib/rsc/html-stream/browser.js +74 -0
  69. package/dist/development/lib/rsc/html-stream/server.js +78 -0
  70. package/dist/development/lib/rsc/route-modules.js +27 -0
  71. package/dist/development/lib/rsc/server.rsc.d.ts +219 -0
  72. package/dist/development/lib/rsc/server.ssr.d.ts +129 -0
  73. package/dist/development/lib/rsc/server.ssr.js +404 -0
  74. package/dist/development/lib/server-runtime/build.d.ts +66 -0
  75. package/dist/development/lib/server-runtime/cookies.d.ts +66 -0
  76. package/dist/development/lib/server-runtime/cookies.js +139 -0
  77. package/dist/development/lib/server-runtime/crypto.js +43 -0
  78. package/dist/development/lib/server-runtime/data.d.ts +13 -0
  79. package/dist/development/lib/server-runtime/data.js +25 -0
  80. package/dist/development/lib/server-runtime/dev.d.ts +9 -0
  81. package/dist/development/lib/server-runtime/dev.js +26 -0
  82. package/dist/development/lib/server-runtime/entry.js +20 -0
  83. package/dist/development/lib/server-runtime/errors.js +75 -0
  84. package/dist/development/lib/server-runtime/headers.js +73 -0
  85. package/dist/development/lib/server-runtime/invariant.js +19 -0
  86. package/dist/development/lib/server-runtime/mode.d.ts +12 -0
  87. package/dist/development/lib/server-runtime/mode.js +25 -0
  88. package/dist/development/lib/server-runtime/routeMatching.js +28 -0
  89. package/dist/development/lib/server-runtime/routes.d.ts +13 -0
  90. package/dist/development/lib/server-runtime/routes.js +74 -0
  91. package/dist/development/lib/server-runtime/server.d.ts +10 -0
  92. package/dist/development/lib/server-runtime/server.js +345 -0
  93. package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
  94. package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
  95. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +45 -0
  96. package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
  97. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +52 -0
  98. package/dist/development/lib/server-runtime/sessions.d.ts +145 -0
  99. package/dist/development/lib/server-runtime/sessions.js +98 -0
  100. package/dist/development/lib/server-runtime/single-fetch.d.ts +7 -0
  101. package/dist/development/lib/server-runtime/single-fetch.js +215 -0
  102. package/dist/development/lib/server-runtime/urls.js +28 -0
  103. package/dist/development/lib/server-runtime/warnings.js +20 -0
  104. package/dist/development/lib/types/future.d.ts +9 -0
  105. package/dist/development/lib/types/internal.d.ts +26 -177
  106. package/dist/development/lib/types/internal.js +3 -2
  107. package/dist/development/{register-roq_0qYo.d.ts → lib/types/register.d.ts} +9 -15
  108. package/dist/development/lib/types/route-data.d.ts +113 -0
  109. package/dist/development/lib/types/route-module-annotations.d.ts +149 -0
  110. package/dist/development/lib/types/route-module.d.ts +19 -0
  111. package/dist/development/lib/types/serializes-to.d.ts +13 -0
  112. package/dist/development/lib/types/utils.d.ts +11 -0
  113. package/dist/development/vendor/turbo-stream-v2/flatten.js +159 -0
  114. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +179 -0
  115. package/dist/development/vendor/turbo-stream-v2/unflatten.js +199 -0
  116. package/dist/development/vendor/turbo-stream-v2/utils.js +39 -0
  117. package/dist/production/dom-export.d.ts +6 -172
  118. package/dist/production/dom-export.js +12 -1009
  119. package/dist/production/index-react-server-client.d.ts +7 -4
  120. package/dist/production/index-react-server-client.js +8 -52
  121. package/dist/production/index-react-server.d.ts +1650 -1641
  122. package/dist/production/index-react-server.js +2873 -3664
  123. package/dist/production/index.d.ts +42 -1476
  124. package/dist/production/index.js +36 -2553
  125. package/dist/production/lib/actions.js +50 -0
  126. package/dist/production/lib/components.d.ts +1030 -0
  127. package/dist/production/lib/components.js +841 -0
  128. package/dist/production/lib/context.d.ts +83 -0
  129. package/dist/production/lib/context.js +41 -0
  130. package/dist/production/lib/dom/dom.d.ts +119 -0
  131. package/dist/production/lib/dom/dom.js +143 -0
  132. package/dist/production/lib/dom/lib.d.ts +2053 -0
  133. package/dist/production/lib/dom/lib.js +1271 -0
  134. package/dist/production/lib/dom/server.d.ts +138 -0
  135. package/dist/production/lib/dom/server.js +301 -0
  136. package/dist/production/lib/dom/ssr/components.d.ts +198 -0
  137. package/dist/production/lib/dom/ssr/components.js +589 -0
  138. package/dist/production/lib/dom/ssr/data.js +29 -0
  139. package/dist/production/lib/dom/ssr/entry.d.ts +60 -0
  140. package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  141. package/dist/production/lib/dom/ssr/errorBoundaries.js +87 -0
  142. package/dist/production/lib/dom/ssr/fallback.js +23 -0
  143. package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
  144. package/dist/production/lib/dom/ssr/fog-of-war.js +180 -0
  145. package/dist/production/lib/dom/ssr/hydration.d.ts +32 -0
  146. package/dist/production/lib/dom/ssr/hydration.js +29 -0
  147. package/dist/production/lib/dom/ssr/invariant.js +16 -0
  148. package/dist/production/lib/dom/ssr/links.js +170 -0
  149. package/dist/production/lib/dom/ssr/markup.js +24 -0
  150. package/dist/production/lib/dom/ssr/routeModules.d.ts +206 -0
  151. package/dist/production/lib/dom/ssr/routeModules.js +31 -0
  152. package/dist/production/lib/dom/ssr/routes-test-stub.d.ts +62 -0
  153. package/dist/production/lib/dom/ssr/routes-test-stub.js +108 -0
  154. package/dist/production/lib/dom/ssr/routes.d.ts +33 -0
  155. package/dist/production/lib/dom/ssr/routes.js +303 -0
  156. package/dist/production/lib/dom/ssr/server.d.ts +48 -0
  157. package/dist/production/lib/dom/ssr/server.js +69 -0
  158. package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
  159. package/dist/production/lib/dom/ssr/single-fetch.js +345 -0
  160. package/dist/production/lib/dom-export/dom-router-provider.d.ts +9 -0
  161. package/dist/production/lib/dom-export/dom-router-provider.js +22 -0
  162. package/dist/production/lib/dom-export/hydrated-router.d.ts +125 -0
  163. package/dist/production/lib/dom-export/hydrated-router.js +150 -0
  164. package/dist/production/lib/errors.js +29 -0
  165. package/dist/production/lib/hooks.d.ts +947 -0
  166. package/dist/production/lib/hooks.js +1373 -0
  167. package/dist/production/lib/href.d.ts +20 -0
  168. package/dist/production/lib/href.js +50 -0
  169. package/dist/production/lib/router/history.d.ts +258 -0
  170. package/dist/production/lib/router/history.js +372 -0
  171. package/dist/production/lib/router/instrumentation.d.ts +86 -0
  172. package/dist/production/lib/router/instrumentation.js +213 -0
  173. package/dist/production/lib/router/links.d.ts +114 -0
  174. package/dist/production/lib/router/router.d.ts +663 -0
  175. package/dist/production/lib/router/router.js +2988 -0
  176. package/dist/production/lib/router/url.js +18 -0
  177. package/dist/production/lib/router/utils.d.ts +948 -0
  178. package/dist/production/lib/router/utils.js +801 -0
  179. package/dist/production/lib/rsc/browser.d.ts +137 -0
  180. package/dist/production/lib/rsc/browser.js +603 -0
  181. package/dist/production/lib/rsc/errorBoundaries.d.ts +11 -0
  182. package/dist/production/lib/rsc/errorBoundaries.js +90 -0
  183. package/dist/production/lib/rsc/html-stream/browser.d.ts +48 -0
  184. package/dist/production/lib/rsc/html-stream/browser.js +74 -0
  185. package/dist/production/lib/rsc/html-stream/server.js +78 -0
  186. package/dist/production/lib/rsc/route-modules.js +27 -0
  187. package/dist/production/lib/rsc/server.rsc.d.ts +219 -0
  188. package/dist/production/lib/rsc/server.ssr.d.ts +129 -0
  189. package/dist/production/lib/rsc/server.ssr.js +404 -0
  190. package/dist/production/lib/server-runtime/build.d.ts +66 -0
  191. package/dist/production/lib/server-runtime/cookies.d.ts +66 -0
  192. package/dist/production/lib/server-runtime/cookies.js +139 -0
  193. package/dist/production/lib/server-runtime/crypto.js +43 -0
  194. package/dist/production/lib/server-runtime/data.d.ts +13 -0
  195. package/dist/production/lib/server-runtime/data.js +25 -0
  196. package/dist/production/lib/server-runtime/dev.d.ts +9 -0
  197. package/dist/production/lib/server-runtime/dev.js +26 -0
  198. package/dist/production/lib/server-runtime/entry.js +20 -0
  199. package/dist/production/lib/server-runtime/errors.js +75 -0
  200. package/dist/production/lib/server-runtime/headers.js +73 -0
  201. package/dist/production/lib/server-runtime/invariant.js +19 -0
  202. package/dist/production/lib/server-runtime/mode.d.ts +12 -0
  203. package/dist/production/lib/server-runtime/mode.js +25 -0
  204. package/dist/production/lib/server-runtime/routeMatching.js +28 -0
  205. package/dist/production/lib/server-runtime/routes.d.ts +13 -0
  206. package/dist/production/lib/server-runtime/routes.js +74 -0
  207. package/dist/production/lib/server-runtime/server.d.ts +10 -0
  208. package/dist/production/lib/server-runtime/server.js +345 -0
  209. package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
  210. package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
  211. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +45 -0
  212. package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
  213. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +52 -0
  214. package/dist/production/lib/server-runtime/sessions.d.ts +145 -0
  215. package/dist/production/lib/server-runtime/sessions.js +98 -0
  216. package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
  217. package/dist/production/lib/server-runtime/single-fetch.js +215 -0
  218. package/dist/production/lib/server-runtime/urls.js +28 -0
  219. package/dist/production/lib/server-runtime/warnings.js +20 -0
  220. package/dist/production/lib/types/future.d.ts +9 -0
  221. package/dist/production/lib/types/internal.d.ts +26 -177
  222. package/dist/production/lib/types/internal.js +3 -2
  223. package/dist/production/{register-roq_0qYo.d.ts → lib/types/register.d.ts} +9 -15
  224. package/dist/production/lib/types/route-data.d.ts +113 -0
  225. package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
  226. package/dist/production/lib/types/route-module.d.ts +19 -0
  227. package/dist/production/lib/types/serializes-to.d.ts +13 -0
  228. package/dist/production/lib/types/utils.d.ts +11 -0
  229. package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
  230. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +179 -0
  231. package/dist/production/vendor/turbo-stream-v2/unflatten.js +199 -0
  232. package/dist/production/vendor/turbo-stream-v2/utils.js +39 -0
  233. package/docs/explanation/code-splitting.md +16 -0
  234. package/docs/how-to/middleware.md +6 -41
  235. package/docs/how-to/react-server-components.md +1 -1
  236. package/docs/upgrading/future.md +0 -249
  237. package/package.json +43 -87
  238. package/dist/development/browser-B2PdsXXH.d.ts +0 -318
  239. package/dist/development/browser-DBmQ1yAR.d.mts +0 -318
  240. package/dist/development/chunk-4ZMWKKQ3.mjs +0 -11606
  241. package/dist/development/chunk-E4MTK73K.mjs +0 -2517
  242. package/dist/development/chunk-U7ORXROY.js +0 -10307
  243. package/dist/development/chunk-WW7PN6QI.js +0 -188
  244. package/dist/development/chunk-YL5M26XI.js +0 -1366
  245. package/dist/development/context-CeD5LmaF.d.mts +0 -1779
  246. package/dist/development/data-CjO11-hU.d.ts +0 -1740
  247. package/dist/development/data-DEjBmEfD.d.mts +0 -1740
  248. package/dist/development/dom-export.d.mts +0 -172
  249. package/dist/development/dom-export.mjs +0 -1010
  250. package/dist/development/index-react-server-client-3ykjivgQ.d.ts +0 -3677
  251. package/dist/development/index-react-server-client-CACgcj2J.d.mts +0 -2614
  252. package/dist/development/index-react-server-client.d.mts +0 -4
  253. package/dist/development/index-react-server-client.mjs +0 -59
  254. package/dist/development/index-react-server.d.mts +0 -2711
  255. package/dist/development/index-react-server.mjs +0 -3803
  256. package/dist/development/index.d.mts +0 -1479
  257. package/dist/development/index.mjs +0 -275
  258. package/dist/development/instrumentation-Dkmpzd13.d.ts +0 -715
  259. package/dist/development/lib/types/internal.d.mts +0 -184
  260. package/dist/development/lib/types/internal.mjs +0 -10
  261. package/dist/development/register-CmkRspdl.d.mts +0 -30
  262. package/dist/production/browser-B2PdsXXH.d.ts +0 -318
  263. package/dist/production/browser-DBmQ1yAR.d.mts +0 -318
  264. package/dist/production/chunk-3Z6WS2WZ.js +0 -188
  265. package/dist/production/chunk-BIP66BKV.js +0 -1366
  266. package/dist/production/chunk-EGOTSXNH.mjs +0 -2517
  267. package/dist/production/chunk-IUPBOWYO.js +0 -10307
  268. package/dist/production/chunk-M7NGGUU6.mjs +0 -11606
  269. package/dist/production/context-CeD5LmaF.d.mts +0 -1779
  270. package/dist/production/data-CjO11-hU.d.ts +0 -1740
  271. package/dist/production/data-DEjBmEfD.d.mts +0 -1740
  272. package/dist/production/dom-export.d.mts +0 -172
  273. package/dist/production/dom-export.mjs +0 -1010
  274. package/dist/production/index-react-server-client-3ykjivgQ.d.ts +0 -3677
  275. package/dist/production/index-react-server-client-CACgcj2J.d.mts +0 -2614
  276. package/dist/production/index-react-server-client.d.mts +0 -4
  277. package/dist/production/index-react-server-client.mjs +0 -59
  278. package/dist/production/index-react-server.d.mts +0 -2711
  279. package/dist/production/index-react-server.mjs +0 -3803
  280. package/dist/production/index.d.mts +0 -1479
  281. package/dist/production/index.mjs +0 -275
  282. package/dist/production/instrumentation-Dkmpzd13.d.ts +0 -715
  283. package/dist/production/lib/types/internal.d.mts +0 -184
  284. package/dist/production/lib/types/internal.mjs +0 -10
  285. package/dist/production/register-CmkRspdl.d.mts +0 -30
@@ -0,0 +1,801 @@
1
+ /**
2
+ * react-router v8.0.0-pre.1
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 { ABSOLUTE_URL_REGEX, PROTOCOL_RELATIVE_URL_REGEX, normalizeProtocolRelativeUrl } from "./url.js";
12
+ import { invariant, parsePath, warning } from "./history.js";
13
+ import * as React$1 from "react";
14
+ //#region lib/router/utils.ts
15
+ /**
16
+ * Creates a type-safe {@link RouterContext} object that can be used to
17
+ * store and retrieve arbitrary values in [`action`](../../start/framework/route-module#action)s,
18
+ * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
19
+ * Similar to React's [`createContext`](https://react.dev/reference/react/createContext),
20
+ * but specifically designed for React Router's request/response lifecycle.
21
+ *
22
+ * If a `defaultValue` is provided, it will be returned from `context.get()`
23
+ * when no value has been set for the context. Otherwise, reading this context
24
+ * when no value has been set will throw an error.
25
+ *
26
+ * ```tsx filename=app/context.ts
27
+ * import { createContext } from "react-router";
28
+ *
29
+ * // Create a context for user data
30
+ * export const userContext =
31
+ * createContext<User | null>(null);
32
+ * ```
33
+ *
34
+ * ```tsx filename=app/middleware/auth.ts
35
+ * import { getUserFromSession } from "~/auth.server";
36
+ * import { userContext } from "~/context";
37
+ *
38
+ * export const authMiddleware = async ({
39
+ * context,
40
+ * request,
41
+ * }) => {
42
+ * const user = await getUserFromSession(request);
43
+ * context.set(userContext, user);
44
+ * };
45
+ * ```
46
+ *
47
+ * ```tsx filename=app/routes/profile.tsx
48
+ * import { userContext } from "~/context";
49
+ *
50
+ * export async function loader({
51
+ * context,
52
+ * }: Route.LoaderArgs) {
53
+ * const user = context.get(userContext);
54
+ *
55
+ * if (!user) {
56
+ * throw new Response("Unauthorized", { status: 401 });
57
+ * }
58
+ *
59
+ * return { user };
60
+ * }
61
+ * ```
62
+ *
63
+ * @public
64
+ * @category Utils
65
+ * @mode framework
66
+ * @mode data
67
+ * @param defaultValue An optional default value for the context. This value
68
+ * will be returned if no value has been set for this context.
69
+ * @returns A {@link RouterContext} object that can be used with
70
+ * `context.get()` and `context.set()` in [`action`](../../start/framework/route-module#action)s,
71
+ * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
72
+ */
73
+ function createContext(defaultValue) {
74
+ return { defaultValue };
75
+ }
76
+ /**
77
+ * Provides methods for writing/reading values in application context in a
78
+ * type-safe way. Primarily for usage with [middleware](../../how-to/middleware).
79
+ *
80
+ * @example
81
+ * import {
82
+ * createContext,
83
+ * RouterContextProvider
84
+ * } from "react-router";
85
+ *
86
+ * const userContext = createContext<User | null>(null);
87
+ * const contextProvider = new RouterContextProvider();
88
+ * contextProvider.set(userContext, getUser());
89
+ * // ^ Type-safe
90
+ * const user = contextProvider.get(userContext);
91
+ * // ^ User
92
+ *
93
+ * @public
94
+ * @category Utils
95
+ * @mode framework
96
+ * @mode data
97
+ */
98
+ var RouterContextProvider = class {
99
+ #map = /* @__PURE__ */ new Map();
100
+ /**
101
+ * Create a new `RouterContextProvider` instance
102
+ * @param init An optional initial context map to populate the provider with
103
+ */
104
+ constructor(init) {
105
+ if (init) for (let [context, value] of init) this.set(context, value);
106
+ }
107
+ /**
108
+ * Access a value from the context. If no value has been set for the context,
109
+ * it will return the context's `defaultValue` if provided, or throw an error
110
+ * if no `defaultValue` was set.
111
+ * @param context The context to get the value for
112
+ * @returns The value for the context, or the context's `defaultValue` if no
113
+ * value was set
114
+ */
115
+ get(context) {
116
+ if (this.#map.has(context)) return this.#map.get(context);
117
+ if (context.defaultValue !== void 0) return context.defaultValue;
118
+ throw new Error("No value found for context");
119
+ }
120
+ /**
121
+ * Set a value for the context. If the context already has a value set, this
122
+ * will overwrite it.
123
+ *
124
+ * @param context The context to set the value for
125
+ * @param value The value to set for the context
126
+ * @returns {void}
127
+ */
128
+ set(context, value) {
129
+ this.#map.set(context, value);
130
+ }
131
+ };
132
+ const unsupportedLazyRouteObjectKeys = new Set([
133
+ "lazy",
134
+ "caseSensitive",
135
+ "path",
136
+ "id",
137
+ "index",
138
+ "children"
139
+ ]);
140
+ function isUnsupportedLazyRouteObjectKey(key) {
141
+ return unsupportedLazyRouteObjectKeys.has(key);
142
+ }
143
+ const unsupportedLazyRouteFunctionKeys = new Set([
144
+ "lazy",
145
+ "caseSensitive",
146
+ "path",
147
+ "id",
148
+ "index",
149
+ "middleware",
150
+ "children"
151
+ ]);
152
+ function isUnsupportedLazyRouteFunctionKey(key) {
153
+ return unsupportedLazyRouteFunctionKeys.has(key);
154
+ }
155
+ function isIndexRoute(route) {
156
+ return route.index === true;
157
+ }
158
+ function defaultMapRouteProperties(route) {
159
+ let updates = {};
160
+ if (route.Component) Object.assign(updates, {
161
+ element: React$1.createElement(route.Component),
162
+ Component: void 0
163
+ });
164
+ if (route.HydrateFallback) Object.assign(updates, {
165
+ hydrateFallbackElement: React$1.createElement(route.HydrateFallback),
166
+ HydrateFallback: void 0
167
+ });
168
+ if (route.ErrorBoundary) Object.assign(updates, {
169
+ errorElement: React$1.createElement(route.ErrorBoundary),
170
+ ErrorBoundary: void 0
171
+ });
172
+ return updates;
173
+ }
174
+ function convertRoutesToDataRoutes(routes, mapRouteProperties = defaultMapRouteProperties, parentPath = [], manifest = {}, allowInPlaceMutations = false) {
175
+ return routes.map((route, index) => {
176
+ let treePath = [...parentPath, String(index)];
177
+ let id = typeof route.id === "string" ? route.id : treePath.join("-");
178
+ invariant(route.index !== true || !route.children, `Cannot specify children on an index route`);
179
+ invariant(allowInPlaceMutations || !manifest[id], `Found a route id collision on id "${id}". Route id's must be globally unique within Data Router usages`);
180
+ if (isIndexRoute(route)) {
181
+ let indexRoute = {
182
+ ...route,
183
+ id
184
+ };
185
+ manifest[id] = mergeRouteUpdates(indexRoute, mapRouteProperties(indexRoute));
186
+ return indexRoute;
187
+ } else {
188
+ let pathOrLayoutRoute = {
189
+ ...route,
190
+ id,
191
+ children: void 0
192
+ };
193
+ manifest[id] = mergeRouteUpdates(pathOrLayoutRoute, mapRouteProperties(pathOrLayoutRoute));
194
+ if (route.children) pathOrLayoutRoute.children = convertRoutesToDataRoutes(route.children, mapRouteProperties, treePath, manifest, allowInPlaceMutations);
195
+ return pathOrLayoutRoute;
196
+ }
197
+ });
198
+ }
199
+ function mergeRouteUpdates(route, updates) {
200
+ return Object.assign(route, {
201
+ ...updates,
202
+ ...typeof updates.lazy === "object" && updates.lazy != null ? { lazy: {
203
+ ...route.lazy,
204
+ ...updates.lazy
205
+ } } : {}
206
+ });
207
+ }
208
+ /**
209
+ * Matches the given routes to a location and returns the match data.
210
+ *
211
+ * @example
212
+ * import { matchRoutes } from "react-router";
213
+ *
214
+ * let routes = [{
215
+ * path: "/",
216
+ * Component: Root,
217
+ * children: [{
218
+ * path: "dashboard",
219
+ * Component: Dashboard,
220
+ * }]
221
+ * }];
222
+ *
223
+ * matchRoutes(routes, "/dashboard"); // [rootMatch, dashboardMatch]
224
+ *
225
+ * @public
226
+ * @category Utils
227
+ * @param routes The array of route objects to match against.
228
+ * @param locationArg The location to match against, either a string path or a
229
+ * partial {@link Location} object
230
+ * @param basename Optional base path to strip from the location before matching.
231
+ * Defaults to `/`.
232
+ * @returns An array of matched routes, or `null` if no matches were found.
233
+ */
234
+ function matchRoutes(routes, locationArg, basename = "/") {
235
+ return matchRoutesImpl(routes, locationArg, basename, false);
236
+ }
237
+ function matchRoutesImpl(routes, locationArg, basename, allowPartial, precomputedBranches) {
238
+ let pathname = stripBasename((typeof locationArg === "string" ? parsePath(locationArg) : locationArg).pathname || "/", basename);
239
+ if (pathname == null) return null;
240
+ let branches = precomputedBranches ?? flattenAndRankRoutes(routes);
241
+ let matches = null;
242
+ let decoded = decodePath(pathname);
243
+ for (let i = 0; matches == null && i < branches.length; ++i) matches = matchRouteBranch(branches[i], decoded, allowPartial);
244
+ return matches;
245
+ }
246
+ function convertRouteMatchToUiMatch(match, loaderData) {
247
+ let { route, pathname, params } = match;
248
+ return {
249
+ id: route.id,
250
+ pathname,
251
+ params,
252
+ loaderData: loaderData[route.id],
253
+ handle: route.handle
254
+ };
255
+ }
256
+ function flattenAndRankRoutes(routes) {
257
+ let branches = flattenRoutes(routes);
258
+ rankRouteBranches(branches);
259
+ return branches;
260
+ }
261
+ function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "", _hasParentOptionalSegments = false) {
262
+ let flattenRoute = (route, index, hasParentOptionalSegments = _hasParentOptionalSegments, relativePath) => {
263
+ let meta = {
264
+ relativePath: relativePath === void 0 ? route.path || "" : relativePath,
265
+ caseSensitive: route.caseSensitive === true,
266
+ childrenIndex: index,
267
+ route
268
+ };
269
+ if (meta.relativePath.startsWith("/")) {
270
+ if (!meta.relativePath.startsWith(parentPath) && hasParentOptionalSegments) return;
271
+ invariant(meta.relativePath.startsWith(parentPath), `Absolute route path "${meta.relativePath}" nested under path "${parentPath}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`);
272
+ meta.relativePath = meta.relativePath.slice(parentPath.length);
273
+ }
274
+ let path = joinPaths([parentPath, meta.relativePath]);
275
+ let routesMeta = parentsMeta.concat(meta);
276
+ if (route.children && route.children.length > 0) {
277
+ invariant(route.index !== true, `Index routes must not have child routes. Please remove all child routes from route path "${path}".`);
278
+ flattenRoutes(route.children, branches, routesMeta, path, hasParentOptionalSegments);
279
+ }
280
+ if (route.path == null && !route.index) return;
281
+ branches.push({
282
+ path,
283
+ score: computeScore(path, route.index),
284
+ routesMeta: routesMeta.map((meta, i) => {
285
+ let [matcher, params] = compilePath(meta.relativePath, meta.caseSensitive, i === routesMeta.length - 1);
286
+ return {
287
+ ...meta,
288
+ matcher,
289
+ compiledParams: params
290
+ };
291
+ })
292
+ });
293
+ };
294
+ routes.forEach((route, index) => {
295
+ if (route.path === "" || !route.path?.includes("?")) flattenRoute(route, index);
296
+ else for (let exploded of explodeOptionalSegments(route.path)) flattenRoute(route, index, true, exploded);
297
+ });
298
+ return branches;
299
+ }
300
+ function explodeOptionalSegments(path) {
301
+ let segments = path.split("/");
302
+ if (segments.length === 0) return [];
303
+ let [first, ...rest] = segments;
304
+ let isOptional = first.endsWith("?");
305
+ let required = first.replace(/\?$/, "");
306
+ if (rest.length === 0) return isOptional ? [required, ""] : [required];
307
+ let restExploded = explodeOptionalSegments(rest.join("/"));
308
+ let result = [];
309
+ result.push(...restExploded.map((subpath) => subpath === "" ? required : [required, subpath].join("/")));
310
+ if (isOptional) result.push(...restExploded);
311
+ return result.map((exploded) => path.startsWith("/") && exploded === "" ? "/" : exploded);
312
+ }
313
+ function rankRouteBranches(branches) {
314
+ branches.sort((a, b) => a.score !== b.score ? b.score - a.score : compareIndexes(a.routesMeta.map((meta) => meta.childrenIndex), b.routesMeta.map((meta) => meta.childrenIndex)));
315
+ }
316
+ const paramRe = /^:[\w-]+$/;
317
+ const dynamicSegmentValue = 3;
318
+ const indexRouteValue = 2;
319
+ const emptySegmentValue = 1;
320
+ const staticSegmentValue = 10;
321
+ const splatPenalty = -2;
322
+ const isSplat = (s) => s === "*";
323
+ function computeScore(path, index) {
324
+ let segments = path.split("/");
325
+ let initialScore = segments.length;
326
+ if (segments.some(isSplat)) initialScore += splatPenalty;
327
+ if (index) initialScore += indexRouteValue;
328
+ return segments.filter((s) => !isSplat(s)).reduce((score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue), initialScore);
329
+ }
330
+ function compareIndexes(a, b) {
331
+ return a.length === b.length && a.slice(0, -1).every((n, i) => n === b[i]) ? a[a.length - 1] - b[b.length - 1] : 0;
332
+ }
333
+ function matchRouteBranch(branch, pathname, allowPartial = false) {
334
+ let { routesMeta } = branch;
335
+ let matchedParams = {};
336
+ let matchedPathname = "/";
337
+ let matches = [];
338
+ for (let i = 0; i < routesMeta.length; ++i) {
339
+ let meta = routesMeta[i];
340
+ let end = i === routesMeta.length - 1;
341
+ let remainingPathname = matchedPathname === "/" ? pathname : pathname.slice(matchedPathname.length) || "/";
342
+ let pattern = {
343
+ path: meta.relativePath,
344
+ caseSensitive: meta.caseSensitive,
345
+ end
346
+ };
347
+ let match = meta.matcher && meta.compiledParams ? matchPathImpl(pattern, remainingPathname, meta.matcher, meta.compiledParams) : matchPath(pattern, remainingPathname);
348
+ let route = meta.route;
349
+ if (!match && end && allowPartial && !routesMeta[routesMeta.length - 1].route.index) match = matchPath({
350
+ path: meta.relativePath,
351
+ caseSensitive: meta.caseSensitive,
352
+ end: false
353
+ }, remainingPathname);
354
+ if (!match) return null;
355
+ Object.assign(matchedParams, match.params);
356
+ matches.push({
357
+ params: matchedParams,
358
+ pathname: joinPaths([matchedPathname, match.pathname]),
359
+ pathnameBase: normalizePathname(joinPaths([matchedPathname, match.pathnameBase])),
360
+ route
361
+ });
362
+ if (match.pathnameBase !== "/") matchedPathname = joinPaths([matchedPathname, match.pathnameBase]);
363
+ }
364
+ return matches;
365
+ }
366
+ /**
367
+ * Returns a path with params interpolated.
368
+ *
369
+ * @example
370
+ * import { generatePath } from "react-router";
371
+ *
372
+ * generatePath("/users/:id", { id: "123" }); // "/users/123"
373
+ *
374
+ * @public
375
+ * @category Utils
376
+ * @param originalPath The original path to generate.
377
+ * @param params The parameters to interpolate into the path.
378
+ * @returns The generated path with parameters interpolated.
379
+ */
380
+ function generatePath(originalPath, params = {}) {
381
+ let path = originalPath;
382
+ if (path.endsWith("*") && path !== "*" && !path.endsWith("/*")) {
383
+ warning(false, `Route path "${path}" will be treated as if it were "${path.replace(/\*$/, "/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${path.replace(/\*$/, "/*")}".`);
384
+ path = path.replace(/\*$/, "/*");
385
+ }
386
+ const prefix = path.startsWith("/") ? "/" : "";
387
+ const stringify = (p) => p == null ? "" : typeof p === "string" ? p : String(p);
388
+ return prefix + path.split(/\/+/).map((segment, index, array) => {
389
+ if (index === array.length - 1 && segment === "*") return stringify(params["*"]);
390
+ const keyMatch = segment.match(/^:([\w-]+)(\??)(.*)/);
391
+ if (keyMatch) {
392
+ const [, key, optional, suffix] = keyMatch;
393
+ let param = params[key];
394
+ invariant(optional === "?" || param != null, `Missing ":${key}" param`);
395
+ return encodeURIComponent(stringify(param)) + suffix;
396
+ }
397
+ return segment.replace(/\?$/g, "");
398
+ }).filter((segment) => !!segment).join("/");
399
+ }
400
+ /**
401
+ * Performs pattern matching on a URL pathname and returns information about
402
+ * the match.
403
+ *
404
+ * @public
405
+ * @category Utils
406
+ * @param pattern The pattern to match against the URL pathname. This can be a
407
+ * string or a {@link PathPattern} object. If a string is provided, it will be
408
+ * treated as a pattern with `caseSensitive` set to `false` and `end` set to
409
+ * `true`.
410
+ * @param pathname The URL pathname to match against the pattern.
411
+ * @returns A path match object if the pattern matches the pathname,
412
+ * or `null` if it does not match.
413
+ */
414
+ function matchPath(pattern, pathname) {
415
+ if (typeof pattern === "string") pattern = {
416
+ path: pattern,
417
+ caseSensitive: false,
418
+ end: true
419
+ };
420
+ let [matcher, compiledParams] = compilePath(pattern.path, pattern.caseSensitive, pattern.end);
421
+ return matchPathImpl(pattern, pathname, matcher, compiledParams);
422
+ }
423
+ function matchPathImpl(pattern, pathname, matcher, compiledParams) {
424
+ let match = pathname.match(matcher);
425
+ if (!match) return null;
426
+ let matchedPathname = match[0];
427
+ let pathnameBase = matchedPathname.replace(/(.)\/+$/, "$1");
428
+ let captureGroups = match.slice(1);
429
+ return {
430
+ params: compiledParams.reduce((memo, { paramName, isOptional }, index) => {
431
+ if (paramName === "*") {
432
+ let splatValue = captureGroups[index] || "";
433
+ pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length).replace(/(.)\/+$/, "$1");
434
+ }
435
+ const value = captureGroups[index];
436
+ if (isOptional && !value) memo[paramName] = void 0;
437
+ else memo[paramName] = (value || "").replace(/%2F/g, "/");
438
+ return memo;
439
+ }, {}),
440
+ pathname: matchedPathname,
441
+ pathnameBase,
442
+ pattern
443
+ };
444
+ }
445
+ function compilePath(path, caseSensitive = false, end = true) {
446
+ warning(path === "*" || !path.endsWith("*") || path.endsWith("/*"), `Route path "${path}" will be treated as if it were "${path.replace(/\*$/, "/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${path.replace(/\*$/, "/*")}".`);
447
+ let params = [];
448
+ let regexpSource = "^" + path.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(/\/:([\w-]+)(\?)?/g, (match, paramName, isOptional, index, str) => {
449
+ params.push({
450
+ paramName,
451
+ isOptional: isOptional != null
452
+ });
453
+ if (isOptional) {
454
+ let nextChar = str.charAt(index + match.length);
455
+ if (nextChar && nextChar !== "/") return "/([^\\/]*)";
456
+ return "(?:/([^\\/]*))?";
457
+ }
458
+ return "/([^\\/]+)";
459
+ }).replace(/\/([\w-]+)\?(\/|$)/g, "(/$1)?$2");
460
+ if (path.endsWith("*")) {
461
+ params.push({ paramName: "*" });
462
+ regexpSource += path === "*" || path === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$";
463
+ } else if (end) regexpSource += "\\/*$";
464
+ else if (path !== "" && path !== "/") regexpSource += "(?:(?=\\/|$))";
465
+ return [new RegExp(regexpSource, caseSensitive ? void 0 : "i"), params];
466
+ }
467
+ function decodePath(value) {
468
+ try {
469
+ return value.split("/").map((v) => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
470
+ } catch (error) {
471
+ warning(false, `The URL path "${value}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${error}).`);
472
+ return value;
473
+ }
474
+ }
475
+ function stripBasename(pathname, basename) {
476
+ if (basename === "/") return pathname;
477
+ if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) return null;
478
+ let startIndex = basename.endsWith("/") ? basename.length - 1 : basename.length;
479
+ let nextChar = pathname.charAt(startIndex);
480
+ if (nextChar && nextChar !== "/") return null;
481
+ return pathname.slice(startIndex) || "/";
482
+ }
483
+ function prependBasename({ basename, pathname }) {
484
+ return pathname === "/" ? basename : joinPaths([basename, pathname]);
485
+ }
486
+ const isAbsoluteUrl = (url) => ABSOLUTE_URL_REGEX.test(url);
487
+ /**
488
+ * Returns a resolved {@link Path} object relative to the given pathname.
489
+ *
490
+ * @public
491
+ * @category Utils
492
+ * @param to The path to resolve, either a string or a partial {@link Path}
493
+ * object.
494
+ * @param fromPathname The pathname to resolve the path from. Defaults to `/`.
495
+ * @returns A {@link Path} object with the resolved pathname, search, and hash.
496
+ */
497
+ function resolvePath(to, fromPathname = "/") {
498
+ let { pathname: toPathname, search = "", hash = "" } = typeof to === "string" ? parsePath(to) : to;
499
+ let pathname;
500
+ if (toPathname) {
501
+ toPathname = removeDoubleSlashes(toPathname);
502
+ if (toPathname.startsWith("/")) pathname = resolvePathname(toPathname.substring(1), "/");
503
+ else pathname = resolvePathname(toPathname, fromPathname);
504
+ } else pathname = fromPathname;
505
+ return {
506
+ pathname,
507
+ search: normalizeSearch(search),
508
+ hash: normalizeHash(hash)
509
+ };
510
+ }
511
+ function resolvePathname(relativePath, fromPathname) {
512
+ let segments = removeTrailingSlash(fromPathname).split("/");
513
+ relativePath.split("/").forEach((segment) => {
514
+ if (segment === "..") {
515
+ if (segments.length > 1) segments.pop();
516
+ } else if (segment !== ".") segments.push(segment);
517
+ });
518
+ return segments.length > 1 ? segments.join("/") : "/";
519
+ }
520
+ function getInvalidPathError(char, field, dest, path) {
521
+ return `Cannot include a '${char}' character in a manually specified \`to.${field}\` field [${JSON.stringify(path)}]. Please separate it out to the \`to.${dest}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`;
522
+ }
523
+ function getPathContributingMatches(matches) {
524
+ return matches.filter((match, index) => index === 0 || match.route.path && match.route.path.length > 0);
525
+ }
526
+ function getResolveToMatches(matches) {
527
+ let pathMatches = getPathContributingMatches(matches);
528
+ return pathMatches.map((match, idx) => idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase);
529
+ }
530
+ function resolveTo(toArg, routePathnames, locationPathname, isPathRelative = false) {
531
+ let to;
532
+ if (typeof toArg === "string") to = parsePath(toArg);
533
+ else {
534
+ to = { ...toArg };
535
+ invariant(!to.pathname || !to.pathname.includes("?"), getInvalidPathError("?", "pathname", "search", to));
536
+ invariant(!to.pathname || !to.pathname.includes("#"), getInvalidPathError("#", "pathname", "hash", to));
537
+ invariant(!to.search || !to.search.includes("#"), getInvalidPathError("#", "search", "hash", to));
538
+ }
539
+ let isEmptyPath = toArg === "" || to.pathname === "";
540
+ let toPathname = isEmptyPath ? "/" : to.pathname;
541
+ let from;
542
+ if (toPathname == null) from = locationPathname;
543
+ else {
544
+ let routePathnameIndex = routePathnames.length - 1;
545
+ if (!isPathRelative && toPathname.startsWith("..")) {
546
+ let toSegments = toPathname.split("/");
547
+ while (toSegments[0] === "..") {
548
+ toSegments.shift();
549
+ routePathnameIndex -= 1;
550
+ }
551
+ to.pathname = toSegments.join("/");
552
+ }
553
+ from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
554
+ }
555
+ let path = resolvePath(to, from);
556
+ let hasExplicitTrailingSlash = toPathname && toPathname !== "/" && toPathname.endsWith("/");
557
+ let hasCurrentTrailingSlash = (isEmptyPath || toPathname === ".") && locationPathname.endsWith("/");
558
+ if (!path.pathname.endsWith("/") && (hasExplicitTrailingSlash || hasCurrentTrailingSlash)) path.pathname += "/";
559
+ return path;
560
+ }
561
+ const removeDoubleSlashes = (path) => path.replace(/[\\/]{2,}/g, "/");
562
+ const joinPaths = (paths) => removeDoubleSlashes(paths.join("/"));
563
+ const removeTrailingSlash = (path) => path.replace(/\/+$/, "");
564
+ const normalizePathname = (pathname) => removeTrailingSlash(pathname).replace(/^\/*/, "/");
565
+ const normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
566
+ const normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
567
+ var DataWithResponseInit = class {
568
+ type = "DataWithResponseInit";
569
+ data;
570
+ init;
571
+ constructor(data, init) {
572
+ this.data = data;
573
+ this.init = init || null;
574
+ }
575
+ };
576
+ /**
577
+ * Create "responses" that contain `headers`/`status` without forcing
578
+ * serialization into an actual [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
579
+ *
580
+ * @example
581
+ * import { data } from "react-router";
582
+ *
583
+ * export async function action({ request }: Route.ActionArgs) {
584
+ * let formData = await request.formData();
585
+ * let item = await createItem(formData);
586
+ * return data(item, {
587
+ * headers: { "X-Custom-Header": "value" }
588
+ * status: 201,
589
+ * });
590
+ * }
591
+ *
592
+ * @public
593
+ * @category Utils
594
+ * @mode framework
595
+ * @mode data
596
+ * @param data The data to be included in the response.
597
+ * @param init The status code or a `ResponseInit` object to be included in the
598
+ * response.
599
+ * @returns A {@link DataWithResponseInit} instance containing the data and
600
+ * response init.
601
+ */
602
+ function data(data, init) {
603
+ return new DataWithResponseInit(data, typeof init === "number" ? { status: init } : init);
604
+ }
605
+ /**
606
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
607
+ * Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
608
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
609
+ *
610
+ * This utility accepts absolute URLs and can navigate to external domains, so
611
+ * the application should validate any user-supplied inputs to redirects.
612
+ *
613
+ * @example
614
+ * import { redirect } from "react-router";
615
+ *
616
+ * export async function loader({ request }: Route.LoaderArgs) {
617
+ * if (!isLoggedIn(request))
618
+ * throw redirect("/login");
619
+ * }
620
+ *
621
+ * // ...
622
+ * }
623
+ *
624
+ * @public
625
+ * @category Utils
626
+ * @mode framework
627
+ * @mode data
628
+ * @param url The URL to redirect to.
629
+ * @param init The status code or a `ResponseInit` object to be included in the
630
+ * response.
631
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
632
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
633
+ * header.
634
+ */
635
+ const redirect = (url, init = 302) => {
636
+ let responseInit = init;
637
+ if (typeof responseInit === "number") responseInit = { status: responseInit };
638
+ else if (typeof responseInit.status === "undefined") responseInit.status = 302;
639
+ let headers = new Headers(responseInit.headers);
640
+ headers.set("Location", url);
641
+ return new Response(null, {
642
+ ...responseInit,
643
+ headers
644
+ });
645
+ };
646
+ /**
647
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
648
+ * that will force a document reload to the new location. Sets the status code
649
+ * and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
650
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
651
+ *
652
+ * This utility accepts absolute URLs and can navigate to external domains, so
653
+ * the application should validate any user-supplied inputs to redirects.
654
+ *
655
+ * ```tsx filename=routes/logout.tsx
656
+ * import { redirectDocument } from "react-router";
657
+ *
658
+ * import { destroySession } from "../sessions.server";
659
+ *
660
+ * export async function action({ request }: Route.ActionArgs) {
661
+ * let session = await getSession(request.headers.get("Cookie"));
662
+ * return redirectDocument("/", {
663
+ * headers: { "Set-Cookie": await destroySession(session) }
664
+ * });
665
+ * }
666
+ * ```
667
+ *
668
+ * @public
669
+ * @category Utils
670
+ * @mode framework
671
+ * @mode data
672
+ * @param url The URL to redirect to.
673
+ * @param init The status code or a `ResponseInit` object to be included in the
674
+ * response.
675
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
676
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
677
+ * header.
678
+ */
679
+ const redirectDocument = (url, init) => {
680
+ let response = redirect(url, init);
681
+ response.headers.set("X-Remix-Reload-Document", "true");
682
+ return response;
683
+ };
684
+ /**
685
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
686
+ * that will perform a [`history.replaceState`](https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState)
687
+ * instead of a [`history.pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
688
+ * for client-side navigation redirects. Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
689
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
690
+ *
691
+ * @example
692
+ * import { replace } from "react-router";
693
+ *
694
+ * export async function loader() {
695
+ * return replace("/new-location");
696
+ * }
697
+ *
698
+ * @public
699
+ * @category Utils
700
+ * @mode framework
701
+ * @mode data
702
+ * @param url The URL to redirect to.
703
+ * @param init The status code or a `ResponseInit` object to be included in the
704
+ * response.
705
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
706
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
707
+ * header.
708
+ */
709
+ const replace = (url, init) => {
710
+ let response = redirect(url, init);
711
+ response.headers.set("X-Remix-Replace", "true");
712
+ return response;
713
+ };
714
+ const SUPPORTED_ERROR_TYPES = [
715
+ "EvalError",
716
+ "RangeError",
717
+ "ReferenceError",
718
+ "SyntaxError",
719
+ "TypeError",
720
+ "URIError"
721
+ ];
722
+ var ErrorResponseImpl = class {
723
+ status;
724
+ statusText;
725
+ data;
726
+ error;
727
+ internal;
728
+ constructor(status, statusText, data, internal = false) {
729
+ this.status = status;
730
+ this.statusText = statusText || "";
731
+ this.internal = internal;
732
+ if (data instanceof Error) {
733
+ this.data = data.toString();
734
+ this.error = data;
735
+ } else this.data = data;
736
+ }
737
+ };
738
+ /**
739
+ * Check if the given error is an {@link ErrorResponse} generated from a 4xx/5xx
740
+ * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
741
+ * thrown from an [`action`](../../start/framework/route-module#action) or
742
+ * [`loader`](../../start/framework/route-module#loader) function.
743
+ *
744
+ * @example
745
+ * import { isRouteErrorResponse } from "react-router";
746
+ *
747
+ * export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
748
+ * if (isRouteErrorResponse(error)) {
749
+ * return (
750
+ * <>
751
+ * <p>Error: `${error.status}: ${error.statusText}`</p>
752
+ * <p>{error.data}</p>
753
+ * </>
754
+ * );
755
+ * }
756
+ *
757
+ * return (
758
+ * <p>Error: {error instanceof Error ? error.message : "Unknown Error"}</p>
759
+ * );
760
+ * }
761
+ *
762
+ * @public
763
+ * @category Utils
764
+ * @mode framework
765
+ * @mode data
766
+ * @param error The error to check.
767
+ * @returns `true` if the error is an {@link ErrorResponse}, `false` otherwise.
768
+ */
769
+ function isRouteErrorResponse(error) {
770
+ return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
771
+ }
772
+ function getRoutePattern(matches) {
773
+ return joinPaths(matches.map((m) => m.route.path).filter(Boolean)) || "/";
774
+ }
775
+ const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
776
+ function parseToInfo(_to, basename) {
777
+ let to = _to;
778
+ if (typeof to !== "string" || !ABSOLUTE_URL_REGEX.test(to)) return {
779
+ absoluteURL: void 0,
780
+ isExternal: false,
781
+ to
782
+ };
783
+ let absoluteURL = to;
784
+ let isExternal = false;
785
+ if (isBrowser) try {
786
+ let currentUrl = new URL(window.location.href);
787
+ let targetUrl = PROTOCOL_RELATIVE_URL_REGEX.test(to) ? new URL(normalizeProtocolRelativeUrl(to, currentUrl.protocol)) : new URL(to);
788
+ let path = stripBasename(targetUrl.pathname, basename);
789
+ if (targetUrl.origin === currentUrl.origin && path != null) to = path + targetUrl.search + targetUrl.hash;
790
+ else isExternal = true;
791
+ } catch (e) {
792
+ warning(false, `<Link to="${to}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`);
793
+ }
794
+ return {
795
+ absoluteURL,
796
+ isExternal,
797
+ to
798
+ };
799
+ }
800
+ //#endregion
801
+ export { ErrorResponseImpl, RouterContextProvider, SUPPORTED_ERROR_TYPES, compilePath, convertRouteMatchToUiMatch, convertRoutesToDataRoutes, createContext, data, decodePath, defaultMapRouteProperties, flattenAndRankRoutes, generatePath, getPathContributingMatches, getResolveToMatches, getRoutePattern, isAbsoluteUrl, isBrowser, isRouteErrorResponse, isUnsupportedLazyRouteFunctionKey, isUnsupportedLazyRouteObjectKey, joinPaths, matchPath, matchRoutes, matchRoutesImpl, parseToInfo, prependBasename, redirect, redirectDocument, removeDoubleSlashes, removeTrailingSlash, replace, resolvePath, resolveTo, stripBasename };