react-router 0.0.0-experimental-bcda00aaf → 0.0.0-experimental-3278f3ca6

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 (84) hide show
  1. package/CHANGELOG.md +0 -7
  2. package/README.md +1 -10
  3. package/dist/dom-export.d.ts +3 -0
  4. package/dist/dom-export.mjs +205 -0
  5. package/dist/dom-export.mjs.map +1 -0
  6. package/dist/index.d.ts +79 -29
  7. package/dist/index.mjs +11726 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/dist/lib/components.d.ts +249 -34
  10. package/dist/lib/context.d.ts +18 -5
  11. package/dist/lib/dom/dom.d.ts +123 -0
  12. package/dist/lib/dom/global.d.ts +40 -0
  13. package/dist/lib/dom/lib.d.ts +940 -0
  14. package/dist/lib/dom/server.d.ts +41 -0
  15. package/dist/lib/dom/ssr/components.d.ts +123 -0
  16. package/dist/lib/dom/ssr/data.d.ts +7 -0
  17. package/dist/lib/dom/ssr/entry.d.ts +47 -0
  18. package/dist/lib/dom/ssr/errorBoundaries.d.ts +36 -0
  19. package/dist/lib/dom/ssr/errors.d.ts +2 -0
  20. package/dist/lib/dom/ssr/fallback.d.ts +2 -0
  21. package/dist/lib/dom/ssr/fog-of-war.d.ts +28 -0
  22. package/dist/lib/dom/ssr/invariant.d.ts +2 -0
  23. package/dist/lib/dom/ssr/links.d.ts +25 -0
  24. package/dist/lib/dom/ssr/markup.d.ts +5 -0
  25. package/dist/lib/dom/ssr/routeModules.d.ts +141 -0
  26. package/dist/lib/dom/ssr/routes-test-stub.d.ts +59 -0
  27. package/dist/lib/dom/ssr/routes.d.ts +32 -0
  28. package/dist/lib/dom/ssr/server.d.ts +16 -0
  29. package/dist/lib/dom/ssr/single-fetch.d.ts +37 -0
  30. package/dist/lib/dom-export/dom-router-provider.d.ts +5 -0
  31. package/dist/lib/dom-export/hydrated-router.d.ts +5 -0
  32. package/dist/lib/hooks.d.ts +284 -55
  33. package/dist/lib/router/history.d.ts +253 -0
  34. package/dist/lib/router/links.d.ts +104 -0
  35. package/dist/lib/router/router.d.ts +540 -0
  36. package/dist/lib/router/utils.d.ts +505 -0
  37. package/dist/lib/server-runtime/build.d.ts +38 -0
  38. package/dist/lib/server-runtime/cookies.d.ts +62 -0
  39. package/dist/lib/server-runtime/crypto.d.ts +2 -0
  40. package/dist/lib/server-runtime/data.d.ts +28 -0
  41. package/dist/lib/server-runtime/dev.d.ts +8 -0
  42. package/dist/lib/server-runtime/entry.d.ts +3 -0
  43. package/dist/lib/server-runtime/errors.d.ts +51 -0
  44. package/dist/lib/server-runtime/formData.d.ts +15 -0
  45. package/dist/lib/server-runtime/headers.d.ts +3 -0
  46. package/dist/lib/server-runtime/invariant.d.ts +2 -0
  47. package/dist/lib/server-runtime/jsonify.d.ts +33 -0
  48. package/dist/lib/server-runtime/markup.d.ts +1 -0
  49. package/dist/lib/server-runtime/mode.d.ts +9 -0
  50. package/dist/lib/server-runtime/responses.d.ts +37 -0
  51. package/dist/lib/server-runtime/routeMatching.d.ts +8 -0
  52. package/dist/lib/server-runtime/routeModules.d.ts +212 -0
  53. package/dist/lib/server-runtime/routes.d.ts +31 -0
  54. package/dist/lib/server-runtime/server.d.ts +5 -0
  55. package/dist/lib/server-runtime/serverHandoff.d.ts +11 -0
  56. package/dist/lib/server-runtime/sessions/cookieStorage.d.ts +19 -0
  57. package/dist/lib/server-runtime/sessions/memoryStorage.d.ts +17 -0
  58. package/dist/lib/server-runtime/sessions.d.ts +140 -0
  59. package/dist/lib/server-runtime/single-fetch.d.ts +30 -0
  60. package/dist/lib/server-runtime/typecheck.d.ts +4 -0
  61. package/dist/lib/server-runtime/upload/errors.d.ts +5 -0
  62. package/dist/lib/server-runtime/upload/memoryUploadHandler.d.ts +21 -0
  63. package/dist/lib/server-runtime/warnings.d.ts +1 -0
  64. package/dist/main-dom-export.js +19 -0
  65. package/dist/main.js +1 -1
  66. package/dist/react-router-dom.development.js +199 -0
  67. package/dist/react-router-dom.development.js.map +1 -0
  68. package/dist/react-router-dom.production.min.js +12 -0
  69. package/dist/react-router-dom.production.min.js.map +1 -0
  70. package/dist/react-router.development.js +12367 -1134
  71. package/dist/react-router.development.js.map +1 -1
  72. package/dist/react-router.production.min.js +2 -2
  73. package/dist/react-router.production.min.js.map +1 -1
  74. package/dist/umd/react-router-dom.development.js +241 -0
  75. package/dist/umd/react-router-dom.development.js.map +1 -0
  76. package/dist/umd/react-router-dom.production.min.js +12 -0
  77. package/dist/umd/react-router-dom.production.min.js.map +1 -0
  78. package/dist/umd/react-router.development.js +12691 -1284
  79. package/dist/umd/react-router.development.js.map +1 -1
  80. package/dist/umd/react-router.production.min.js +2 -2
  81. package/dist/umd/react-router.production.min.js.map +1 -1
  82. package/package.json +32 -6
  83. package/dist/index.js +0 -1471
  84. package/dist/index.js.map +0 -1
package/dist/index.js DELETED
@@ -1,1471 +0,0 @@
1
- /**
2
- * React Router v0.0.0-experimental-bcda00aaf
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 * as React from 'react';
12
- import { UNSAFE_invariant, joinPaths, matchPath, UNSAFE_decodePath, UNSAFE_getResolveToMatches, UNSAFE_warning, resolveTo, parsePath, matchRoutes, Action, UNSAFE_convertRouteMatchToUiMatch, stripBasename, IDLE_BLOCKER, isRouteErrorResponse, createMemoryHistory, AbortedDeferredError, createRouter } from '@remix-run/router';
13
- export { AbortedDeferredError, Action as NavigationType, createPath, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, replace, resolvePath } from '@remix-run/router';
14
-
15
- function _extends() {
16
- _extends = Object.assign ? Object.assign.bind() : function (target) {
17
- for (var i = 1; i < arguments.length; i++) {
18
- var source = arguments[i];
19
- for (var key in source) {
20
- if (Object.prototype.hasOwnProperty.call(source, key)) {
21
- target[key] = source[key];
22
- }
23
- }
24
- }
25
- return target;
26
- };
27
- return _extends.apply(this, arguments);
28
- }
29
-
30
- // Create react-specific types from the agnostic types in @remix-run/router to
31
- // export from react-router
32
- const DataRouterContext = /*#__PURE__*/React.createContext(null);
33
- if (process.env.NODE_ENV !== "production") {
34
- DataRouterContext.displayName = "DataRouter";
35
- }
36
- const DataRouterStateContext = /*#__PURE__*/React.createContext(null);
37
- if (process.env.NODE_ENV !== "production") {
38
- DataRouterStateContext.displayName = "DataRouterState";
39
- }
40
- const AwaitContext = /*#__PURE__*/React.createContext(null);
41
- if (process.env.NODE_ENV !== "production") {
42
- AwaitContext.displayName = "Await";
43
- }
44
-
45
- /**
46
- * A Navigator is a "location changer"; it's how you get to different locations.
47
- *
48
- * Every history instance conforms to the Navigator interface, but the
49
- * distinction is useful primarily when it comes to the low-level `<Router>` API
50
- * where both the location and a navigator must be provided separately in order
51
- * to avoid "tearing" that may occur in a suspense-enabled app if the action
52
- * and/or location were to be read directly from the history instance.
53
- */
54
-
55
- const NavigationContext = /*#__PURE__*/React.createContext(null);
56
- if (process.env.NODE_ENV !== "production") {
57
- NavigationContext.displayName = "Navigation";
58
- }
59
- const LocationContext = /*#__PURE__*/React.createContext(null);
60
- if (process.env.NODE_ENV !== "production") {
61
- LocationContext.displayName = "Location";
62
- }
63
- const RouteContext = /*#__PURE__*/React.createContext({
64
- outlet: null,
65
- matches: [],
66
- isDataRoute: false
67
- });
68
- if (process.env.NODE_ENV !== "production") {
69
- RouteContext.displayName = "Route";
70
- }
71
- const RouteErrorContext = /*#__PURE__*/React.createContext(null);
72
- if (process.env.NODE_ENV !== "production") {
73
- RouteErrorContext.displayName = "RouteError";
74
- }
75
-
76
- /**
77
- * Returns the full href for the given "to" value. This is useful for building
78
- * custom links that are also accessible and preserve right-click behavior.
79
- *
80
- * @see https://reactrouter.com/hooks/use-href
81
- */
82
- function useHref(to, _temp) {
83
- let {
84
- relative
85
- } = _temp === void 0 ? {} : _temp;
86
- !useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
87
- // router loaded. We can help them understand how to avoid that.
88
- "useHref() may be used only in the context of a <Router> component.") : UNSAFE_invariant(false) : void 0;
89
- let {
90
- basename,
91
- navigator
92
- } = React.useContext(NavigationContext);
93
- let {
94
- hash,
95
- pathname,
96
- search
97
- } = useResolvedPath(to, {
98
- relative
99
- });
100
- let joinedPathname = pathname;
101
-
102
- // If we're operating within a basename, prepend it to the pathname prior
103
- // to creating the href. If this is a root navigation, then just use the raw
104
- // basename which allows the basename to have full control over the presence
105
- // of a trailing slash on root links
106
- if (basename !== "/") {
107
- joinedPathname = pathname === "/" ? basename : joinPaths([basename, pathname]);
108
- }
109
- return navigator.createHref({
110
- pathname: joinedPathname,
111
- search,
112
- hash
113
- });
114
- }
115
-
116
- /**
117
- * Returns true if this component is a descendant of a `<Router>`.
118
- *
119
- * @see https://reactrouter.com/hooks/use-in-router-context
120
- */
121
- function useInRouterContext() {
122
- return React.useContext(LocationContext) != null;
123
- }
124
-
125
- /**
126
- * Returns the current location object, which represents the current URL in web
127
- * browsers.
128
- *
129
- * Note: If you're using this it may mean you're doing some of your own
130
- * "routing" in your app, and we'd like to know what your use case is. We may
131
- * be able to provide something higher-level to better suit your needs.
132
- *
133
- * @see https://reactrouter.com/hooks/use-location
134
- */
135
- function useLocation() {
136
- !useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
137
- // router loaded. We can help them understand how to avoid that.
138
- "useLocation() may be used only in the context of a <Router> component.") : UNSAFE_invariant(false) : void 0;
139
- return React.useContext(LocationContext).location;
140
- }
141
-
142
- /**
143
- * Returns the current navigation action which describes how the router came to
144
- * the current location, either by a pop, push, or replace on the history stack.
145
- *
146
- * @see https://reactrouter.com/hooks/use-navigation-type
147
- */
148
- function useNavigationType() {
149
- return React.useContext(LocationContext).navigationType;
150
- }
151
-
152
- /**
153
- * Returns a PathMatch object if the given pattern matches the current URL.
154
- * This is useful for components that need to know "active" state, e.g.
155
- * `<NavLink>`.
156
- *
157
- * @see https://reactrouter.com/hooks/use-match
158
- */
159
- function useMatch(pattern) {
160
- !useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
161
- // router loaded. We can help them understand how to avoid that.
162
- "useMatch() may be used only in the context of a <Router> component.") : UNSAFE_invariant(false) : void 0;
163
- let {
164
- pathname
165
- } = useLocation();
166
- return React.useMemo(() => matchPath(pattern, UNSAFE_decodePath(pathname)), [pathname, pattern]);
167
- }
168
-
169
- /**
170
- * The interface for the navigate() function returned from useNavigate().
171
- */
172
-
173
- const navigateEffectWarning = "You should call navigate() in a React.useEffect(), not when " + "your component is first rendered.";
174
-
175
- // Mute warnings for calls to useNavigate in SSR environments
176
- function useIsomorphicLayoutEffect(cb) {
177
- let isStatic = React.useContext(NavigationContext).static;
178
- if (!isStatic) {
179
- // We should be able to get rid of this once react 18.3 is released
180
- // See: https://github.com/facebook/react/pull/26395
181
- // eslint-disable-next-line react-hooks/rules-of-hooks
182
- React.useLayoutEffect(cb);
183
- }
184
- }
185
-
186
- /**
187
- * Returns an imperative method for changing the location. Used by `<Link>`s, but
188
- * may also be used by other elements to change the location.
189
- *
190
- * @see https://reactrouter.com/hooks/use-navigate
191
- */
192
- function useNavigate() {
193
- let {
194
- isDataRoute
195
- } = React.useContext(RouteContext);
196
- // Conditional usage is OK here because the usage of a data router is static
197
- // eslint-disable-next-line react-hooks/rules-of-hooks
198
- return isDataRoute ? useNavigateStable() : useNavigateUnstable();
199
- }
200
- function useNavigateUnstable() {
201
- !useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
202
- // router loaded. We can help them understand how to avoid that.
203
- "useNavigate() may be used only in the context of a <Router> component.") : UNSAFE_invariant(false) : void 0;
204
- let dataRouterContext = React.useContext(DataRouterContext);
205
- let {
206
- basename,
207
- future,
208
- navigator
209
- } = React.useContext(NavigationContext);
210
- let {
211
- matches
212
- } = React.useContext(RouteContext);
213
- let {
214
- pathname: locationPathname
215
- } = useLocation();
216
- let routePathnamesJson = JSON.stringify(UNSAFE_getResolveToMatches(matches, future.v7_relativeSplatPath));
217
- let activeRef = React.useRef(false);
218
- useIsomorphicLayoutEffect(() => {
219
- activeRef.current = true;
220
- });
221
- let navigate = React.useCallback(function (to, options) {
222
- if (options === void 0) {
223
- options = {};
224
- }
225
- process.env.NODE_ENV !== "production" ? UNSAFE_warning(activeRef.current, navigateEffectWarning) : void 0;
226
-
227
- // Short circuit here since if this happens on first render the navigate
228
- // is useless because we haven't wired up our history listener yet
229
- if (!activeRef.current) return;
230
- if (typeof to === "number") {
231
- navigator.go(to);
232
- return;
233
- }
234
- let path = resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, options.relative === "path");
235
-
236
- // If we're operating within a basename, prepend it to the pathname prior
237
- // to handing off to history (but only if we're not in a data router,
238
- // otherwise it'll prepend the basename inside of the router).
239
- // If this is a root navigation, then we navigate to the raw basename
240
- // which allows the basename to have full control over the presence of a
241
- // trailing slash on root links
242
- if (dataRouterContext == null && basename !== "/") {
243
- path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
244
- }
245
- (!!options.replace ? navigator.replace : navigator.push)(path, options.state, options);
246
- }, [basename, navigator, routePathnamesJson, locationPathname, dataRouterContext]);
247
- return navigate;
248
- }
249
- const OutletContext = /*#__PURE__*/React.createContext(null);
250
-
251
- /**
252
- * Returns the context (if provided) for the child route at this level of the route
253
- * hierarchy.
254
- * @see https://reactrouter.com/hooks/use-outlet-context
255
- */
256
- function useOutletContext() {
257
- return React.useContext(OutletContext);
258
- }
259
-
260
- /**
261
- * Returns the element for the child route at this level of the route
262
- * hierarchy. Used internally by `<Outlet>` to render child routes.
263
- *
264
- * @see https://reactrouter.com/hooks/use-outlet
265
- */
266
- function useOutlet(context) {
267
- let outlet = React.useContext(RouteContext).outlet;
268
- if (outlet) {
269
- return /*#__PURE__*/React.createElement(OutletContext.Provider, {
270
- value: context
271
- }, outlet);
272
- }
273
- return outlet;
274
- }
275
-
276
- /**
277
- * Returns an object of key/value pairs of the dynamic params from the current
278
- * URL that were matched by the route path.
279
- *
280
- * @see https://reactrouter.com/hooks/use-params
281
- */
282
- function useParams() {
283
- let {
284
- matches
285
- } = React.useContext(RouteContext);
286
- let routeMatch = matches[matches.length - 1];
287
- return routeMatch ? routeMatch.params : {};
288
- }
289
-
290
- /**
291
- * Resolves the pathname of the given `to` value against the current location.
292
- *
293
- * @see https://reactrouter.com/hooks/use-resolved-path
294
- */
295
- function useResolvedPath(to, _temp2) {
296
- let {
297
- relative
298
- } = _temp2 === void 0 ? {} : _temp2;
299
- let {
300
- future
301
- } = React.useContext(NavigationContext);
302
- let {
303
- matches
304
- } = React.useContext(RouteContext);
305
- let {
306
- pathname: locationPathname
307
- } = useLocation();
308
- let routePathnamesJson = JSON.stringify(UNSAFE_getResolveToMatches(matches, future.v7_relativeSplatPath));
309
- return React.useMemo(() => resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, relative === "path"), [to, routePathnamesJson, locationPathname, relative]);
310
- }
311
-
312
- /**
313
- * Returns the element of the route that matched the current location, prepared
314
- * with the correct context to render the remainder of the route tree. Route
315
- * elements in the tree must render an `<Outlet>` to render their child route's
316
- * element.
317
- *
318
- * @see https://reactrouter.com/hooks/use-routes
319
- */
320
- function useRoutes(routes, locationArg) {
321
- return useRoutesImpl(routes, locationArg);
322
- }
323
-
324
- // Internal implementation with accept optional param for RouterProvider usage
325
- function useRoutesImpl(routes, locationArg, dataRouterState, future) {
326
- !useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
327
- // router loaded. We can help them understand how to avoid that.
328
- "useRoutes() may be used only in the context of a <Router> component.") : UNSAFE_invariant(false) : void 0;
329
- let {
330
- navigator
331
- } = React.useContext(NavigationContext);
332
- let {
333
- matches: parentMatches
334
- } = React.useContext(RouteContext);
335
- let routeMatch = parentMatches[parentMatches.length - 1];
336
- let parentParams = routeMatch ? routeMatch.params : {};
337
- let parentPathname = routeMatch ? routeMatch.pathname : "/";
338
- let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
339
- let parentRoute = routeMatch && routeMatch.route;
340
- if (process.env.NODE_ENV !== "production") {
341
- // You won't get a warning about 2 different <Routes> under a <Route>
342
- // without a trailing *, but this is a best-effort warning anyway since we
343
- // cannot even give the warning unless they land at the parent route.
344
- //
345
- // Example:
346
- //
347
- // <Routes>
348
- // {/* This route path MUST end with /* because otherwise
349
- // it will never match /blog/post/123 */}
350
- // <Route path="blog" element={<Blog />} />
351
- // <Route path="blog/feed" element={<BlogFeed />} />
352
- // </Routes>
353
- //
354
- // function Blog() {
355
- // return (
356
- // <Routes>
357
- // <Route path="post/:id" element={<Post />} />
358
- // </Routes>
359
- // );
360
- // }
361
- let parentPath = parentRoute && parentRoute.path || "";
362
- warningOnce(parentPathname, !parentRoute || 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\n" + ("Please change the parent <Route path=\"" + parentPath + "\"> to <Route ") + ("path=\"" + (parentPath === "/" ? "*" : parentPath + "/*") + "\">."));
363
- }
364
- let locationFromContext = useLocation();
365
- let location;
366
- if (locationArg) {
367
- var _parsedLocationArg$pa;
368
- let parsedLocationArg = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
369
- !(parentPathnameBase === "/" || ((_parsedLocationArg$pa = parsedLocationArg.pathname) == null ? void 0 : _parsedLocationArg$pa.startsWith(parentPathnameBase))) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "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.")) : UNSAFE_invariant(false) : void 0;
370
- location = parsedLocationArg;
371
- } else {
372
- location = locationFromContext;
373
- }
374
- let pathname = location.pathname || "/";
375
- let remainingPathname = pathname;
376
- if (parentPathnameBase !== "/") {
377
- // Determine the remaining pathname by removing the # of URL segments the
378
- // parentPathnameBase has, instead of removing based on character count.
379
- // This is because we can't guarantee that incoming/outgoing encodings/
380
- // decodings will match exactly.
381
- // We decode paths before matching on a per-segment basis with
382
- // decodeURIComponent(), but we re-encode pathnames via `new URL()` so they
383
- // match what `window.location.pathname` would reflect. Those don't 100%
384
- // align when it comes to encoded URI characters such as % and &.
385
- //
386
- // So we may end up with:
387
- // pathname: "/descendant/a%25b/match"
388
- // parentPathnameBase: "/descendant/a%b"
389
- //
390
- // And the direct substring removal approach won't work :/
391
- let parentSegments = parentPathnameBase.replace(/^\//, "").split("/");
392
- let segments = pathname.replace(/^\//, "").split("/");
393
- remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
394
- }
395
- let matches = dataRouterState && parentPathnameBase === "/" ?
396
- // If we're rendering at the top level of a data router, we've already
397
- // matched routes in the router so use those and avoid calling
398
- // `matchRoutes` again
399
- dataRouterState.matches : matchRoutes(routes, {
400
- pathname: remainingPathname
401
- });
402
- if (process.env.NODE_ENV !== "production") {
403
- process.env.NODE_ENV !== "production" ? UNSAFE_warning(parentRoute || matches != null, "No routes matched location \"" + location.pathname + location.search + location.hash + "\" ") : void 0;
404
- process.env.NODE_ENV !== "production" ? UNSAFE_warning(matches == null || matches[matches.length - 1].route.element !== undefined || matches[matches.length - 1].route.Component !== undefined || matches[matches.length - 1].route.lazy !== undefined, "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.") : void 0;
405
- }
406
- let renderedMatches = _renderMatches(matches && matches.map(match => Object.assign({}, match, {
407
- params: Object.assign({}, parentParams, match.params),
408
- pathname: joinPaths([parentPathnameBase,
409
- // Re-encode pathnames that were decoded inside matchRoutes
410
- navigator.encodeLocation ? navigator.encodeLocation(match.pathname).pathname : match.pathname]),
411
- pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([parentPathnameBase,
412
- // Re-encode pathnames that were decoded inside matchRoutes
413
- navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase).pathname : match.pathnameBase])
414
- })), parentMatches, dataRouterState, future);
415
-
416
- // When a user passes in a `locationArg`, the associated routes need to
417
- // be wrapped in a new `LocationContext.Provider` in order for `useLocation`
418
- // to use the scoped location instead of the global location.
419
- if (locationArg && renderedMatches) {
420
- return /*#__PURE__*/React.createElement(LocationContext.Provider, {
421
- value: {
422
- location: _extends({
423
- pathname: "/",
424
- search: "",
425
- hash: "",
426
- state: null,
427
- key: "default"
428
- }, location),
429
- navigationType: Action.Pop
430
- }
431
- }, renderedMatches);
432
- }
433
- return renderedMatches;
434
- }
435
- function DefaultErrorComponent() {
436
- let error = useRouteError();
437
- let message = isRouteErrorResponse(error) ? error.status + " " + error.statusText : error instanceof Error ? error.message : JSON.stringify(error);
438
- let stack = error instanceof Error ? error.stack : null;
439
- let lightgrey = "rgba(200,200,200, 0.5)";
440
- let preStyles = {
441
- padding: "0.5rem",
442
- backgroundColor: lightgrey
443
- };
444
- let codeStyles = {
445
- padding: "2px 4px",
446
- backgroundColor: lightgrey
447
- };
448
- let devInfo = null;
449
- if (process.env.NODE_ENV !== "production") {
450
- console.error("Error handled by React Router default ErrorBoundary:", error);
451
- devInfo = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("p", null, "\uD83D\uDCBF Hey developer \uD83D\uDC4B"), /*#__PURE__*/React.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /*#__PURE__*/React.createElement("code", {
452
- style: codeStyles
453
- }, "ErrorBoundary"), " or", " ", /*#__PURE__*/React.createElement("code", {
454
- style: codeStyles
455
- }, "errorElement"), " prop on your route."));
456
- }
457
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("h2", null, "Unexpected Application Error!"), /*#__PURE__*/React.createElement("h3", {
458
- style: {
459
- fontStyle: "italic"
460
- }
461
- }, message), stack ? /*#__PURE__*/React.createElement("pre", {
462
- style: preStyles
463
- }, stack) : null, devInfo);
464
- }
465
- const defaultErrorElement = /*#__PURE__*/React.createElement(DefaultErrorComponent, null);
466
- class RenderErrorBoundary extends React.Component {
467
- constructor(props) {
468
- super(props);
469
- this.state = {
470
- location: props.location,
471
- revalidation: props.revalidation,
472
- error: props.error
473
- };
474
- }
475
- static getDerivedStateFromError(error) {
476
- return {
477
- error: error
478
- };
479
- }
480
- static getDerivedStateFromProps(props, state) {
481
- // When we get into an error state, the user will likely click "back" to the
482
- // previous page that didn't have an error. Because this wraps the entire
483
- // application, that will have no effect--the error page continues to display.
484
- // This gives us a mechanism to recover from the error when the location changes.
485
- //
486
- // Whether we're in an error state or not, we update the location in state
487
- // so that when we are in an error state, it gets reset when a new location
488
- // comes in and the user recovers from the error.
489
- if (state.location !== props.location || state.revalidation !== "idle" && props.revalidation === "idle") {
490
- return {
491
- error: props.error,
492
- location: props.location,
493
- revalidation: props.revalidation
494
- };
495
- }
496
-
497
- // If we're not changing locations, preserve the location but still surface
498
- // any new errors that may come through. We retain the existing error, we do
499
- // this because the error provided from the app state may be cleared without
500
- // the location changing.
501
- return {
502
- error: props.error !== undefined ? props.error : state.error,
503
- location: state.location,
504
- revalidation: props.revalidation || state.revalidation
505
- };
506
- }
507
- componentDidCatch(error, errorInfo) {
508
- console.error("React Router caught the following error during render", error, errorInfo);
509
- }
510
- render() {
511
- return this.state.error !== undefined ? /*#__PURE__*/React.createElement(RouteContext.Provider, {
512
- value: this.props.routeContext
513
- }, /*#__PURE__*/React.createElement(RouteErrorContext.Provider, {
514
- value: this.state.error,
515
- children: this.props.component
516
- })) : this.props.children;
517
- }
518
- }
519
- function RenderedRoute(_ref) {
520
- let {
521
- routeContext,
522
- match,
523
- children
524
- } = _ref;
525
- let dataRouterContext = React.useContext(DataRouterContext);
526
-
527
- // Track how deep we got in our render pass to emulate SSR componentDidCatch
528
- // in a DataStaticRouter
529
- if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) {
530
- dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
531
- }
532
- return /*#__PURE__*/React.createElement(RouteContext.Provider, {
533
- value: routeContext
534
- }, children);
535
- }
536
- function _renderMatches(matches, parentMatches, dataRouterState, future) {
537
- var _dataRouterState;
538
- if (parentMatches === void 0) {
539
- parentMatches = [];
540
- }
541
- if (dataRouterState === void 0) {
542
- dataRouterState = null;
543
- }
544
- if (future === void 0) {
545
- future = null;
546
- }
547
- if (matches == null) {
548
- var _future;
549
- if (!dataRouterState) {
550
- return null;
551
- }
552
- if (dataRouterState.errors) {
553
- // Don't bail if we have data router errors so we can render them in the
554
- // boundary. Use the pre-matched (or shimmed) matches
555
- matches = dataRouterState.matches;
556
- } else if ((_future = future) != null && _future.v7_partialHydration && parentMatches.length === 0 && !dataRouterState.initialized && dataRouterState.matches.length > 0) {
557
- // Don't bail if we're initializing with partial hydration and we have
558
- // router matches. That means we're actively running `patchRoutesOnNavigation`
559
- // so we should render down the partial matches to the appropriate
560
- // `HydrateFallback`. We only do this if `parentMatches` is empty so it
561
- // only impacts the root matches for `RouterProvider` and no descendant
562
- // `<Routes>`
563
- matches = dataRouterState.matches;
564
- } else {
565
- return null;
566
- }
567
- }
568
- let renderedMatches = matches;
569
-
570
- // If we have data errors, trim matches to the highest error boundary
571
- let errors = (_dataRouterState = dataRouterState) == null ? void 0 : _dataRouterState.errors;
572
- if (errors != null) {
573
- let errorIndex = renderedMatches.findIndex(m => m.route.id && (errors == null ? void 0 : errors[m.route.id]) !== undefined);
574
- !(errorIndex >= 0) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "Could not find a matching route for errors on route IDs: " + Object.keys(errors).join(",")) : UNSAFE_invariant(false) : void 0;
575
- renderedMatches = renderedMatches.slice(0, Math.min(renderedMatches.length, errorIndex + 1));
576
- }
577
-
578
- // If we're in a partial hydration mode, detect if we need to render down to
579
- // a given HydrateFallback while we load the rest of the hydration data
580
- let renderFallback = false;
581
- let fallbackIndex = -1;
582
- if (dataRouterState && future && future.v7_partialHydration) {
583
- for (let i = 0; i < renderedMatches.length; i++) {
584
- let match = renderedMatches[i];
585
- // Track the deepest fallback up until the first route without data
586
- if (match.route.HydrateFallback || match.route.hydrateFallbackElement) {
587
- fallbackIndex = i;
588
- }
589
- if (match.route.id) {
590
- let {
591
- loaderData,
592
- errors
593
- } = dataRouterState;
594
- let needsToRunLoader = match.route.loader && loaderData[match.route.id] === undefined && (!errors || errors[match.route.id] === undefined);
595
- if (match.route.lazy || needsToRunLoader) {
596
- // We found the first route that's not ready to render (waiting on
597
- // lazy, or has a loader that hasn't run yet). Flag that we need to
598
- // render a fallback and render up until the appropriate fallback
599
- renderFallback = true;
600
- if (fallbackIndex >= 0) {
601
- renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
602
- } else {
603
- renderedMatches = [renderedMatches[0]];
604
- }
605
- break;
606
- }
607
- }
608
- }
609
- }
610
- return renderedMatches.reduceRight((outlet, match, index) => {
611
- // Only data routers handle errors/fallbacks
612
- let error;
613
- let shouldRenderHydrateFallback = false;
614
- let errorElement = null;
615
- let hydrateFallbackElement = null;
616
- if (dataRouterState) {
617
- error = errors && match.route.id ? errors[match.route.id] : undefined;
618
- errorElement = match.route.errorElement || defaultErrorElement;
619
- if (renderFallback) {
620
- if (fallbackIndex < 0 && index === 0) {
621
- warningOnce("route-fallback", false, "No `HydrateFallback` element provided to render during initial hydration");
622
- shouldRenderHydrateFallback = true;
623
- hydrateFallbackElement = null;
624
- } else if (fallbackIndex === index) {
625
- shouldRenderHydrateFallback = true;
626
- hydrateFallbackElement = match.route.hydrateFallbackElement || null;
627
- }
628
- }
629
- }
630
- let matches = parentMatches.concat(renderedMatches.slice(0, index + 1));
631
- let getChildren = () => {
632
- let children;
633
- if (error) {
634
- children = errorElement;
635
- } else if (shouldRenderHydrateFallback) {
636
- children = hydrateFallbackElement;
637
- } else if (match.route.Component) {
638
- // Note: This is a de-optimized path since React won't re-use the
639
- // ReactElement since it's identity changes with each new
640
- // React.createElement call. We keep this so folks can use
641
- // `<Route Component={...}>` in `<Routes>` but generally `Component`
642
- // usage is only advised in `RouterProvider` when we can convert it to
643
- // `element` ahead of time.
644
- children = /*#__PURE__*/React.createElement(match.route.Component, null);
645
- } else if (match.route.element) {
646
- children = match.route.element;
647
- } else {
648
- children = outlet;
649
- }
650
- return /*#__PURE__*/React.createElement(RenderedRoute, {
651
- match: match,
652
- routeContext: {
653
- outlet,
654
- matches,
655
- isDataRoute: dataRouterState != null
656
- },
657
- children: children
658
- });
659
- };
660
- // Only wrap in an error boundary within data router usages when we have an
661
- // ErrorBoundary/errorElement on this route. Otherwise let it bubble up to
662
- // an ancestor ErrorBoundary/errorElement
663
- return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? /*#__PURE__*/React.createElement(RenderErrorBoundary, {
664
- location: dataRouterState.location,
665
- revalidation: dataRouterState.revalidation,
666
- component: errorElement,
667
- error: error,
668
- children: getChildren(),
669
- routeContext: {
670
- outlet: null,
671
- matches,
672
- isDataRoute: true
673
- }
674
- }) : getChildren();
675
- }, null);
676
- }
677
- var DataRouterHook = /*#__PURE__*/function (DataRouterHook) {
678
- DataRouterHook["UseBlocker"] = "useBlocker";
679
- DataRouterHook["UseRevalidator"] = "useRevalidator";
680
- DataRouterHook["UseNavigateStable"] = "useNavigate";
681
- return DataRouterHook;
682
- }(DataRouterHook || {});
683
- var DataRouterStateHook = /*#__PURE__*/function (DataRouterStateHook) {
684
- DataRouterStateHook["UseBlocker"] = "useBlocker";
685
- DataRouterStateHook["UseLoaderData"] = "useLoaderData";
686
- DataRouterStateHook["UseActionData"] = "useActionData";
687
- DataRouterStateHook["UseRouteError"] = "useRouteError";
688
- DataRouterStateHook["UseNavigation"] = "useNavigation";
689
- DataRouterStateHook["UseRouteLoaderData"] = "useRouteLoaderData";
690
- DataRouterStateHook["UseMatches"] = "useMatches";
691
- DataRouterStateHook["UseRevalidator"] = "useRevalidator";
692
- DataRouterStateHook["UseNavigateStable"] = "useNavigate";
693
- DataRouterStateHook["UseRouteId"] = "useRouteId";
694
- return DataRouterStateHook;
695
- }(DataRouterStateHook || {});
696
- function getDataRouterConsoleError(hookName) {
697
- return hookName + " must be used within a data router. See https://reactrouter.com/routers/picking-a-router.";
698
- }
699
- function useDataRouterContext(hookName) {
700
- let ctx = React.useContext(DataRouterContext);
701
- !ctx ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : UNSAFE_invariant(false) : void 0;
702
- return ctx;
703
- }
704
- function useDataRouterState(hookName) {
705
- let state = React.useContext(DataRouterStateContext);
706
- !state ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : UNSAFE_invariant(false) : void 0;
707
- return state;
708
- }
709
- function useRouteContext(hookName) {
710
- let route = React.useContext(RouteContext);
711
- !route ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : UNSAFE_invariant(false) : void 0;
712
- return route;
713
- }
714
-
715
- // Internal version with hookName-aware debugging
716
- function useCurrentRouteId(hookName) {
717
- let route = useRouteContext(hookName);
718
- let thisRoute = route.matches[route.matches.length - 1];
719
- !thisRoute.route.id ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, hookName + " can only be used on routes that contain a unique \"id\"") : UNSAFE_invariant(false) : void 0;
720
- return thisRoute.route.id;
721
- }
722
-
723
- /**
724
- * Returns the ID for the nearest contextual route
725
- */
726
- function useRouteId() {
727
- return useCurrentRouteId(DataRouterStateHook.UseRouteId);
728
- }
729
-
730
- /**
731
- * Returns the current navigation, defaulting to an "idle" navigation when
732
- * no navigation is in progress
733
- */
734
- function useNavigation() {
735
- let state = useDataRouterState(DataRouterStateHook.UseNavigation);
736
- return state.navigation;
737
- }
738
-
739
- /**
740
- * Returns a revalidate function for manually triggering revalidation, as well
741
- * as the current state of any manual revalidations
742
- */
743
- function useRevalidator() {
744
- let dataRouterContext = useDataRouterContext(DataRouterHook.UseRevalidator);
745
- let state = useDataRouterState(DataRouterStateHook.UseRevalidator);
746
- return React.useMemo(() => ({
747
- revalidate: dataRouterContext.router.revalidate,
748
- state: state.revalidation
749
- }), [dataRouterContext.router.revalidate, state.revalidation]);
750
- }
751
-
752
- /**
753
- * Returns the active route matches, useful for accessing loaderData for
754
- * parent/child routes or the route "handle" property
755
- */
756
- function useMatches() {
757
- let {
758
- matches,
759
- loaderData
760
- } = useDataRouterState(DataRouterStateHook.UseMatches);
761
- return React.useMemo(() => matches.map(m => UNSAFE_convertRouteMatchToUiMatch(m, loaderData)), [matches, loaderData]);
762
- }
763
-
764
- /**
765
- * Returns the loader data for the nearest ancestor Route loader
766
- */
767
- function useLoaderData() {
768
- let state = useDataRouterState(DataRouterStateHook.UseLoaderData);
769
- let routeId = useCurrentRouteId(DataRouterStateHook.UseLoaderData);
770
- if (state.errors && state.errors[routeId] != null) {
771
- console.error("You cannot `useLoaderData` in an errorElement (routeId: " + routeId + ")");
772
- return undefined;
773
- }
774
- return state.loaderData[routeId];
775
- }
776
-
777
- /**
778
- * Returns the loaderData for the given routeId
779
- */
780
- function useRouteLoaderData(routeId) {
781
- let state = useDataRouterState(DataRouterStateHook.UseRouteLoaderData);
782
- return state.loaderData[routeId];
783
- }
784
-
785
- /**
786
- * Returns the action data for the nearest ancestor Route action
787
- */
788
- function useActionData() {
789
- let state = useDataRouterState(DataRouterStateHook.UseActionData);
790
- let routeId = useCurrentRouteId(DataRouterStateHook.UseLoaderData);
791
- return state.actionData ? state.actionData[routeId] : undefined;
792
- }
793
-
794
- /**
795
- * Returns the nearest ancestor Route error, which could be a loader/action
796
- * error or a render error. This is intended to be called from your
797
- * ErrorBoundary/errorElement to display a proper error message.
798
- */
799
- function useRouteError() {
800
- var _state$errors;
801
- let error = React.useContext(RouteErrorContext);
802
- let state = useDataRouterState(DataRouterStateHook.UseRouteError);
803
- let routeId = useCurrentRouteId(DataRouterStateHook.UseRouteError);
804
-
805
- // If this was a render error, we put it in a RouteError context inside
806
- // of RenderErrorBoundary
807
- if (error !== undefined) {
808
- return error;
809
- }
810
-
811
- // Otherwise look for errors from our data router state
812
- return (_state$errors = state.errors) == null ? void 0 : _state$errors[routeId];
813
- }
814
-
815
- /**
816
- * Returns the happy-path data from the nearest ancestor `<Await />` value
817
- */
818
- function useAsyncValue() {
819
- let value = React.useContext(AwaitContext);
820
- return value == null ? void 0 : value._data;
821
- }
822
-
823
- /**
824
- * Returns the error from the nearest ancestor `<Await />` value
825
- */
826
- function useAsyncError() {
827
- let value = React.useContext(AwaitContext);
828
- return value == null ? void 0 : value._error;
829
- }
830
- let blockerId = 0;
831
-
832
- /**
833
- * Allow the application to block navigations within the SPA and present the
834
- * user a confirmation dialog to confirm the navigation. Mostly used to avoid
835
- * using half-filled form data. This does not handle hard-reloads or
836
- * cross-origin navigations.
837
- */
838
- function useBlocker(shouldBlock) {
839
- let {
840
- router,
841
- basename
842
- } = useDataRouterContext(DataRouterHook.UseBlocker);
843
- let state = useDataRouterState(DataRouterStateHook.UseBlocker);
844
- let [blockerKey, setBlockerKey] = React.useState("");
845
- let blockerFunction = React.useCallback(arg => {
846
- if (typeof shouldBlock !== "function") {
847
- return !!shouldBlock;
848
- }
849
- if (basename === "/") {
850
- return shouldBlock(arg);
851
- }
852
-
853
- // If they provided us a function and we've got an active basename, strip
854
- // it from the locations we expose to the user to match the behavior of
855
- // useLocation
856
- let {
857
- currentLocation,
858
- nextLocation,
859
- historyAction
860
- } = arg;
861
- return shouldBlock({
862
- currentLocation: _extends({}, currentLocation, {
863
- pathname: stripBasename(currentLocation.pathname, basename) || currentLocation.pathname
864
- }),
865
- nextLocation: _extends({}, nextLocation, {
866
- pathname: stripBasename(nextLocation.pathname, basename) || nextLocation.pathname
867
- }),
868
- historyAction
869
- });
870
- }, [basename, shouldBlock]);
871
-
872
- // This effect is in charge of blocker key assignment and deletion (which is
873
- // tightly coupled to the key)
874
- React.useEffect(() => {
875
- let key = String(++blockerId);
876
- setBlockerKey(key);
877
- return () => router.deleteBlocker(key);
878
- }, [router]);
879
-
880
- // This effect handles assigning the blockerFunction. This is to handle
881
- // unstable blocker function identities, and happens only after the prior
882
- // effect so we don't get an orphaned blockerFunction in the router with a
883
- // key of "". Until then we just have the IDLE_BLOCKER.
884
- React.useEffect(() => {
885
- if (blockerKey !== "") {
886
- router.getBlocker(blockerKey, blockerFunction);
887
- }
888
- }, [router, blockerKey, blockerFunction]);
889
-
890
- // Prefer the blocker from `state` not `router.state` since DataRouterContext
891
- // is memoized so this ensures we update on blocker state updates
892
- return blockerKey && state.blockers.has(blockerKey) ? state.blockers.get(blockerKey) : IDLE_BLOCKER;
893
- }
894
-
895
- /**
896
- * Stable version of useNavigate that is used when we are in the context of
897
- * a RouterProvider.
898
- */
899
- function useNavigateStable() {
900
- let {
901
- router
902
- } = useDataRouterContext(DataRouterHook.UseNavigateStable);
903
- let id = useCurrentRouteId(DataRouterStateHook.UseNavigateStable);
904
- let activeRef = React.useRef(false);
905
- useIsomorphicLayoutEffect(() => {
906
- activeRef.current = true;
907
- });
908
- let navigate = React.useCallback(function (to, options) {
909
- if (options === void 0) {
910
- options = {};
911
- }
912
- process.env.NODE_ENV !== "production" ? UNSAFE_warning(activeRef.current, navigateEffectWarning) : void 0;
913
-
914
- // Short circuit here since if this happens on first render the navigate
915
- // is useless because we haven't wired up our router subscriber yet
916
- if (!activeRef.current) return;
917
- if (typeof to === "number") {
918
- router.navigate(to);
919
- } else {
920
- router.navigate(to, _extends({
921
- fromRouteId: id
922
- }, options));
923
- }
924
- }, [router, id]);
925
- return navigate;
926
- }
927
- const alreadyWarned = {};
928
- function warningOnce(key, cond, message) {
929
- if (!cond && !alreadyWarned[key]) {
930
- alreadyWarned[key] = true;
931
- process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, message) : void 0;
932
- }
933
- }
934
-
935
- /**
936
- Webpack + React 17 fails to compile on any of the following because webpack
937
- complains that `startTransition` doesn't exist in `React`:
938
- * import { startTransition } from "react"
939
- * import * as React from from "react";
940
- "startTransition" in React ? React.startTransition(() => setState()) : setState()
941
- * import * as React from from "react";
942
- "startTransition" in React ? React["startTransition"](() => setState()) : setState()
943
-
944
- Moving it to a constant such as the following solves the Webpack/React 17 issue:
945
- * import * as React from from "react";
946
- const START_TRANSITION = "startTransition";
947
- START_TRANSITION in React ? React[START_TRANSITION](() => setState()) : setState()
948
-
949
- However, that introduces webpack/terser minification issues in production builds
950
- in React 18 where minification/obfuscation ends up removing the call of
951
- React.startTransition entirely from the first half of the ternary. Grabbing
952
- this exported reference once up front resolves that issue.
953
-
954
- See https://github.com/remix-run/react-router/issues/10579
955
- */
956
- const START_TRANSITION = "startTransition";
957
- const startTransitionImpl = React[START_TRANSITION];
958
-
959
- /**
960
- * Given a Remix Router instance, render the appropriate UI
961
- */
962
- function RouterProvider(_ref) {
963
- let {
964
- fallbackElement,
965
- router,
966
- future
967
- } = _ref;
968
- let [state, setStateImpl] = React.useState(router.state);
969
- let {
970
- v7_startTransition
971
- } = future || {};
972
- let setState = React.useCallback(newState => {
973
- if (v7_startTransition && startTransitionImpl) {
974
- startTransitionImpl(() => setStateImpl(newState));
975
- } else {
976
- setStateImpl(newState);
977
- }
978
- }, [setStateImpl, v7_startTransition]);
979
-
980
- // Need to use a layout effect here so we are subscribed early enough to
981
- // pick up on any render-driven redirects/navigations (useEffect/<Navigate>)
982
- React.useLayoutEffect(() => router.subscribe(setState), [router, setState]);
983
- React.useEffect(() => {
984
- process.env.NODE_ENV !== "production" ? UNSAFE_warning(fallbackElement == null || !router.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using " + "`v7_partialHydration`, use a `HydrateFallback` component instead") : void 0;
985
- // Only log this once on initial mount
986
- // eslint-disable-next-line react-hooks/exhaustive-deps
987
- }, []);
988
- let navigator = React.useMemo(() => {
989
- return {
990
- createHref: router.createHref,
991
- encodeLocation: router.encodeLocation,
992
- go: n => router.navigate(n),
993
- push: (to, state, opts) => router.navigate(to, {
994
- state,
995
- preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
996
- }),
997
- replace: (to, state, opts) => router.navigate(to, {
998
- replace: true,
999
- state,
1000
- preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
1001
- })
1002
- };
1003
- }, [router]);
1004
- let basename = router.basename || "/";
1005
- let dataRouterContext = React.useMemo(() => ({
1006
- router,
1007
- navigator,
1008
- static: false,
1009
- basename
1010
- }), [router, navigator, basename]);
1011
-
1012
- // The fragment and {null} here are important! We need them to keep React 18's
1013
- // useId happy when we are server-rendering since we may have a <script> here
1014
- // containing the hydrated server-side staticContext (from StaticRouterProvider).
1015
- // useId relies on the component tree structure to generate deterministic id's
1016
- // so we need to ensure it remains the same on the client even though
1017
- // we don't need the <script> tag
1018
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DataRouterContext.Provider, {
1019
- value: dataRouterContext
1020
- }, /*#__PURE__*/React.createElement(DataRouterStateContext.Provider, {
1021
- value: state
1022
- }, /*#__PURE__*/React.createElement(Router, {
1023
- basename: basename,
1024
- location: state.location,
1025
- navigationType: state.historyAction,
1026
- navigator: navigator,
1027
- future: {
1028
- v7_relativeSplatPath: router.future.v7_relativeSplatPath
1029
- }
1030
- }, state.initialized || router.future.v7_partialHydration ? /*#__PURE__*/React.createElement(DataRoutes, {
1031
- routes: router.routes,
1032
- future: router.future,
1033
- state: state
1034
- }) : fallbackElement))), null);
1035
- }
1036
- function DataRoutes(_ref2) {
1037
- let {
1038
- routes,
1039
- future,
1040
- state
1041
- } = _ref2;
1042
- return useRoutesImpl(routes, undefined, state, future);
1043
- }
1044
- /**
1045
- * A `<Router>` that stores all entries in memory.
1046
- *
1047
- * @see https://reactrouter.com/router-components/memory-router
1048
- */
1049
- function MemoryRouter(_ref3) {
1050
- let {
1051
- basename,
1052
- children,
1053
- initialEntries,
1054
- initialIndex,
1055
- future
1056
- } = _ref3;
1057
- let historyRef = React.useRef();
1058
- if (historyRef.current == null) {
1059
- historyRef.current = createMemoryHistory({
1060
- initialEntries,
1061
- initialIndex,
1062
- v5Compat: true
1063
- });
1064
- }
1065
- let history = historyRef.current;
1066
- let [state, setStateImpl] = React.useState({
1067
- action: history.action,
1068
- location: history.location
1069
- });
1070
- let {
1071
- v7_startTransition
1072
- } = future || {};
1073
- let setState = React.useCallback(newState => {
1074
- v7_startTransition && startTransitionImpl ? startTransitionImpl(() => setStateImpl(newState)) : setStateImpl(newState);
1075
- }, [setStateImpl, v7_startTransition]);
1076
- React.useLayoutEffect(() => history.listen(setState), [history, setState]);
1077
- return /*#__PURE__*/React.createElement(Router, {
1078
- basename: basename,
1079
- children: children,
1080
- location: state.location,
1081
- navigationType: state.action,
1082
- navigator: history,
1083
- future: future
1084
- });
1085
- }
1086
- /**
1087
- * Changes the current location.
1088
- *
1089
- * Note: This API is mostly useful in React.Component subclasses that are not
1090
- * able to use hooks. In functional components, we recommend you use the
1091
- * `useNavigate` hook instead.
1092
- *
1093
- * @see https://reactrouter.com/components/navigate
1094
- */
1095
- function Navigate(_ref4) {
1096
- let {
1097
- to,
1098
- replace,
1099
- state,
1100
- relative
1101
- } = _ref4;
1102
- !useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of
1103
- // the router loaded. We can help them understand how to avoid that.
1104
- "<Navigate> may be used only in the context of a <Router> component.") : UNSAFE_invariant(false) : void 0;
1105
- let {
1106
- future,
1107
- static: isStatic
1108
- } = React.useContext(NavigationContext);
1109
- process.env.NODE_ENV !== "production" ? UNSAFE_warning(!isStatic, "<Navigate> must not be used on the initial render in a <StaticRouter>. " + "This is a no-op, but you should modify your code so the <Navigate> is " + "only ever rendered in response to some user interaction or state change.") : void 0;
1110
- let {
1111
- matches
1112
- } = React.useContext(RouteContext);
1113
- let {
1114
- pathname: locationPathname
1115
- } = useLocation();
1116
- let navigate = useNavigate();
1117
-
1118
- // Resolve the path outside of the effect so that when effects run twice in
1119
- // StrictMode they navigate to the same place
1120
- let path = resolveTo(to, UNSAFE_getResolveToMatches(matches, future.v7_relativeSplatPath), locationPathname, relative === "path");
1121
- let jsonPath = JSON.stringify(path);
1122
- React.useEffect(() => navigate(JSON.parse(jsonPath), {
1123
- replace,
1124
- state,
1125
- relative
1126
- }), [navigate, jsonPath, relative, replace, state]);
1127
- return null;
1128
- }
1129
- /**
1130
- * Renders the child route's element, if there is one.
1131
- *
1132
- * @see https://reactrouter.com/components/outlet
1133
- */
1134
- function Outlet(props) {
1135
- return useOutlet(props.context);
1136
- }
1137
- /**
1138
- * Declares an element that should be rendered at a certain URL path.
1139
- *
1140
- * @see https://reactrouter.com/components/route
1141
- */
1142
- function Route(_props) {
1143
- process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "A <Route> is only ever to be used as the child of <Routes> element, " + "never rendered directly. Please wrap your <Route> in a <Routes>.") : UNSAFE_invariant(false) ;
1144
- }
1145
- /**
1146
- * Provides location context for the rest of the app.
1147
- *
1148
- * Note: You usually won't render a `<Router>` directly. Instead, you'll render a
1149
- * router that is more specific to your environment such as a `<BrowserRouter>`
1150
- * in web browsers or a `<StaticRouter>` for server rendering.
1151
- *
1152
- * @see https://reactrouter.com/router-components/router
1153
- */
1154
- function Router(_ref5) {
1155
- let {
1156
- basename: basenameProp = "/",
1157
- children = null,
1158
- location: locationProp,
1159
- navigationType = Action.Pop,
1160
- navigator,
1161
- static: staticProp = false,
1162
- future
1163
- } = _ref5;
1164
- !!useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "You cannot render a <Router> inside another <Router>." + " You should never have more than one in your app.") : UNSAFE_invariant(false) : void 0;
1165
-
1166
- // Preserve trailing slashes on basename, so we can let the user control
1167
- // the enforcement of trailing slashes throughout the app
1168
- let basename = basenameProp.replace(/^\/*/, "/");
1169
- let navigationContext = React.useMemo(() => ({
1170
- basename,
1171
- navigator,
1172
- static: staticProp,
1173
- future: _extends({
1174
- v7_relativeSplatPath: false
1175
- }, future)
1176
- }), [basename, future, navigator, staticProp]);
1177
- if (typeof locationProp === "string") {
1178
- locationProp = parsePath(locationProp);
1179
- }
1180
- let {
1181
- pathname = "/",
1182
- search = "",
1183
- hash = "",
1184
- state = null,
1185
- key = "default"
1186
- } = locationProp;
1187
- let locationContext = React.useMemo(() => {
1188
- let trailingPathname = stripBasename(pathname, basename);
1189
- if (trailingPathname == null) {
1190
- return null;
1191
- }
1192
- return {
1193
- location: {
1194
- pathname: trailingPathname,
1195
- search,
1196
- hash,
1197
- state,
1198
- key
1199
- },
1200
- navigationType
1201
- };
1202
- }, [basename, pathname, search, hash, state, key, navigationType]);
1203
- process.env.NODE_ENV !== "production" ? UNSAFE_warning(locationContext != null, "<Router basename=\"" + basename + "\"> is not able to match the URL " + ("\"" + pathname + search + hash + "\" because it does not start with the ") + "basename, so the <Router> won't render anything.") : void 0;
1204
- if (locationContext == null) {
1205
- return null;
1206
- }
1207
- return /*#__PURE__*/React.createElement(NavigationContext.Provider, {
1208
- value: navigationContext
1209
- }, /*#__PURE__*/React.createElement(LocationContext.Provider, {
1210
- children: children,
1211
- value: locationContext
1212
- }));
1213
- }
1214
- /**
1215
- * A container for a nested tree of `<Route>` elements that renders the branch
1216
- * that best matches the current location.
1217
- *
1218
- * @see https://reactrouter.com/components/routes
1219
- */
1220
- function Routes(_ref6) {
1221
- let {
1222
- children,
1223
- location
1224
- } = _ref6;
1225
- return useRoutes(createRoutesFromChildren(children), location);
1226
- }
1227
- /**
1228
- * Component to use for rendering lazily loaded data from returning defer()
1229
- * in a loader function
1230
- */
1231
- function Await(_ref7) {
1232
- let {
1233
- children,
1234
- errorElement,
1235
- resolve
1236
- } = _ref7;
1237
- return /*#__PURE__*/React.createElement(AwaitErrorBoundary, {
1238
- resolve: resolve,
1239
- errorElement: errorElement
1240
- }, /*#__PURE__*/React.createElement(ResolveAwait, null, children));
1241
- }
1242
- var AwaitRenderStatus = /*#__PURE__*/function (AwaitRenderStatus) {
1243
- AwaitRenderStatus[AwaitRenderStatus["pending"] = 0] = "pending";
1244
- AwaitRenderStatus[AwaitRenderStatus["success"] = 1] = "success";
1245
- AwaitRenderStatus[AwaitRenderStatus["error"] = 2] = "error";
1246
- return AwaitRenderStatus;
1247
- }(AwaitRenderStatus || {});
1248
- const neverSettledPromise = new Promise(() => {});
1249
- class AwaitErrorBoundary extends React.Component {
1250
- constructor(props) {
1251
- super(props);
1252
- this.state = {
1253
- error: null
1254
- };
1255
- }
1256
- static getDerivedStateFromError(error) {
1257
- return {
1258
- error
1259
- };
1260
- }
1261
- componentDidCatch(error, errorInfo) {
1262
- console.error("<Await> caught the following error during render", error, errorInfo);
1263
- }
1264
- render() {
1265
- let {
1266
- children,
1267
- errorElement,
1268
- resolve
1269
- } = this.props;
1270
- let promise = null;
1271
- let status = AwaitRenderStatus.pending;
1272
- if (!(resolve instanceof Promise)) {
1273
- // Didn't get a promise - provide as a resolved promise
1274
- status = AwaitRenderStatus.success;
1275
- promise = Promise.resolve();
1276
- Object.defineProperty(promise, "_tracked", {
1277
- get: () => true
1278
- });
1279
- Object.defineProperty(promise, "_data", {
1280
- get: () => resolve
1281
- });
1282
- } else if (this.state.error) {
1283
- // Caught a render error, provide it as a rejected promise
1284
- status = AwaitRenderStatus.error;
1285
- let renderError = this.state.error;
1286
- promise = Promise.reject().catch(() => {}); // Avoid unhandled rejection warnings
1287
- Object.defineProperty(promise, "_tracked", {
1288
- get: () => true
1289
- });
1290
- Object.defineProperty(promise, "_error", {
1291
- get: () => renderError
1292
- });
1293
- } else if (resolve._tracked) {
1294
- // Already tracked promise - check contents
1295
- promise = resolve;
1296
- status = "_error" in promise ? AwaitRenderStatus.error : "_data" in promise ? AwaitRenderStatus.success : AwaitRenderStatus.pending;
1297
- } else {
1298
- // Raw (untracked) promise - track it
1299
- status = AwaitRenderStatus.pending;
1300
- Object.defineProperty(resolve, "_tracked", {
1301
- get: () => true
1302
- });
1303
- promise = resolve.then(data => Object.defineProperty(resolve, "_data", {
1304
- get: () => data
1305
- }), error => Object.defineProperty(resolve, "_error", {
1306
- get: () => error
1307
- }));
1308
- }
1309
- if (status === AwaitRenderStatus.error && promise._error instanceof AbortedDeferredError) {
1310
- // Freeze the UI by throwing a never resolved promise
1311
- throw neverSettledPromise;
1312
- }
1313
- if (status === AwaitRenderStatus.error && !errorElement) {
1314
- // No errorElement, throw to the nearest route-level error boundary
1315
- throw promise._error;
1316
- }
1317
- if (status === AwaitRenderStatus.error) {
1318
- // Render via our errorElement
1319
- return /*#__PURE__*/React.createElement(AwaitContext.Provider, {
1320
- value: promise,
1321
- children: errorElement
1322
- });
1323
- }
1324
- if (status === AwaitRenderStatus.success) {
1325
- // Render children with resolved value
1326
- return /*#__PURE__*/React.createElement(AwaitContext.Provider, {
1327
- value: promise,
1328
- children: children
1329
- });
1330
- }
1331
-
1332
- // Throw to the suspense boundary
1333
- throw promise;
1334
- }
1335
- }
1336
-
1337
- /**
1338
- * @private
1339
- * Indirection to leverage useAsyncValue for a render-prop API on `<Await>`
1340
- */
1341
- function ResolveAwait(_ref8) {
1342
- let {
1343
- children
1344
- } = _ref8;
1345
- let data = useAsyncValue();
1346
- let toRender = typeof children === "function" ? children(data) : children;
1347
- return /*#__PURE__*/React.createElement(React.Fragment, null, toRender);
1348
- }
1349
-
1350
- ///////////////////////////////////////////////////////////////////////////////
1351
- // UTILS
1352
- ///////////////////////////////////////////////////////////////////////////////
1353
-
1354
- /**
1355
- * Creates a route config from a React "children" object, which is usually
1356
- * either a `<Route>` element or an array of them. Used internally by
1357
- * `<Routes>` to create a route config from its children.
1358
- *
1359
- * @see https://reactrouter.com/utils/create-routes-from-children
1360
- */
1361
- function createRoutesFromChildren(children, parentPath) {
1362
- if (parentPath === void 0) {
1363
- parentPath = [];
1364
- }
1365
- let routes = [];
1366
- React.Children.forEach(children, (element, index) => {
1367
- if (! /*#__PURE__*/React.isValidElement(element)) {
1368
- // Ignore non-elements. This allows people to more easily inline
1369
- // conditionals in their route config.
1370
- return;
1371
- }
1372
- let treePath = [...parentPath, index];
1373
- if (element.type === React.Fragment) {
1374
- // Transparently support React.Fragment and its children.
1375
- routes.push.apply(routes, createRoutesFromChildren(element.props.children, treePath));
1376
- return;
1377
- }
1378
- !(element.type === Route) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "[" + (typeof element.type === "string" ? element.type : element.type.name) + "] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>") : UNSAFE_invariant(false) : void 0;
1379
- !(!element.props.index || !element.props.children) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "An index route cannot have child routes.") : UNSAFE_invariant(false) : void 0;
1380
- let route = {
1381
- id: element.props.id || treePath.join("-"),
1382
- caseSensitive: element.props.caseSensitive,
1383
- element: element.props.element,
1384
- Component: element.props.Component,
1385
- index: element.props.index,
1386
- path: element.props.path,
1387
- loader: element.props.loader,
1388
- action: element.props.action,
1389
- errorElement: element.props.errorElement,
1390
- ErrorBoundary: element.props.ErrorBoundary,
1391
- hasErrorBoundary: element.props.ErrorBoundary != null || element.props.errorElement != null,
1392
- shouldRevalidate: element.props.shouldRevalidate,
1393
- handle: element.props.handle,
1394
- lazy: element.props.lazy
1395
- };
1396
- if (element.props.children) {
1397
- route.children = createRoutesFromChildren(element.props.children, treePath);
1398
- }
1399
- routes.push(route);
1400
- });
1401
- return routes;
1402
- }
1403
-
1404
- /**
1405
- * Renders the result of `matchRoutes()` into a React element.
1406
- */
1407
- function renderMatches(matches) {
1408
- return _renderMatches(matches);
1409
- }
1410
-
1411
- function mapRouteProperties(route) {
1412
- let updates = {
1413
- // Note: this check also occurs in createRoutesFromChildren so update
1414
- // there if you change this -- please and thank you!
1415
- hasErrorBoundary: route.ErrorBoundary != null || route.errorElement != null
1416
- };
1417
- if (route.Component) {
1418
- if (process.env.NODE_ENV !== "production") {
1419
- if (route.element) {
1420
- process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "You should not include both `Component` and `element` on your route - " + "`Component` will be used.") : void 0;
1421
- }
1422
- }
1423
- Object.assign(updates, {
1424
- element: /*#__PURE__*/React.createElement(route.Component),
1425
- Component: undefined
1426
- });
1427
- }
1428
- if (route.HydrateFallback) {
1429
- if (process.env.NODE_ENV !== "production") {
1430
- if (route.hydrateFallbackElement) {
1431
- process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "You should not include both `HydrateFallback` and `hydrateFallbackElement` on your route - " + "`HydrateFallback` will be used.") : void 0;
1432
- }
1433
- }
1434
- Object.assign(updates, {
1435
- hydrateFallbackElement: /*#__PURE__*/React.createElement(route.HydrateFallback),
1436
- HydrateFallback: undefined
1437
- });
1438
- }
1439
- if (route.ErrorBoundary) {
1440
- if (process.env.NODE_ENV !== "production") {
1441
- if (route.errorElement) {
1442
- process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "You should not include both `ErrorBoundary` and `errorElement` on your route - " + "`ErrorBoundary` will be used.") : void 0;
1443
- }
1444
- }
1445
- Object.assign(updates, {
1446
- errorElement: /*#__PURE__*/React.createElement(route.ErrorBoundary),
1447
- ErrorBoundary: undefined
1448
- });
1449
- }
1450
- return updates;
1451
- }
1452
- function createMemoryRouter(routes, opts) {
1453
- return createRouter({
1454
- basename: opts == null ? void 0 : opts.basename,
1455
- future: _extends({}, opts == null ? void 0 : opts.future, {
1456
- v7_prependBasename: true
1457
- }),
1458
- history: createMemoryHistory({
1459
- initialEntries: opts == null ? void 0 : opts.initialEntries,
1460
- initialIndex: opts == null ? void 0 : opts.initialIndex
1461
- }),
1462
- hydrationData: opts == null ? void 0 : opts.hydrationData,
1463
- routes,
1464
- mapRouteProperties,
1465
- dataStrategy: opts == null ? void 0 : opts.dataStrategy,
1466
- patchRoutesOnNavigation: opts == null ? void 0 : opts.patchRoutesOnNavigation
1467
- }).initialize();
1468
- }
1469
-
1470
- export { Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RouteContext as UNSAFE_RouteContext, mapRouteProperties as UNSAFE_mapRouteProperties, useRouteId as UNSAFE_useRouteId, useRoutesImpl as UNSAFE_useRoutesImpl, createMemoryRouter, createRoutesFromChildren, createRoutesFromChildren as createRoutesFromElements, renderMatches, useActionData, useAsyncError, useAsyncValue, useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes };
1471
- //# sourceMappingURL=index.js.map