UNPKG

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