UNPKG

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