UNPKG

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