| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 |
|
| 11 | (function (global, factory) {
|
| 12 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@remix-run/router'), require('react')) :
|
| 13 | typeof define === 'function' && define.amd ? define(['exports', '@remix-run/router', 'react'], factory) :
|
| 14 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactRouter = {}, global.RemixRouter, global.React));
|
| 15 | })(this, (function (exports, router, React) { 'use strict';
|
| 16 |
|
| 17 | function _interopNamespace(e) {
|
| 18 | if (e && e.__esModule) return e;
|
| 19 | var n = Object.create(null);
|
| 20 | if (e) {
|
| 21 | Object.keys(e).forEach(function (k) {
|
| 22 | if (k !== 'default') {
|
| 23 | var d = Object.getOwnPropertyDescriptor(e, k);
|
| 24 | Object.defineProperty(n, k, d.get ? d : {
|
| 25 | enumerable: true,
|
| 26 | get: function () { return e[k]; }
|
| 27 | });
|
| 28 | }
|
| 29 | });
|
| 30 | }
|
| 31 | n["default"] = e;
|
| 32 | return Object.freeze(n);
|
| 33 | }
|
| 34 |
|
| 35 | var React__namespace = _interopNamespace(React);
|
| 36 |
|
| 37 | function _extends() {
|
| 38 | _extends = Object.assign ? Object.assign.bind() : function (target) {
|
| 39 | for (var i = 1; i < arguments.length; i++) {
|
| 40 | var source = arguments[i];
|
| 41 |
|
| 42 | for (var key in source) {
|
| 43 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
| 44 | target[key] = source[key];
|
| 45 | }
|
| 46 | }
|
| 47 | }
|
| 48 |
|
| 49 | return target;
|
| 50 | };
|
| 51 | return _extends.apply(this, arguments);
|
| 52 | }
|
| 53 |
|
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 |
|
| 60 | |
| 61 | |
| 62 | |
| 63 |
|
| 64 |
|
| 65 | function isPolyfill(x, y) {
|
| 66 | return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y
|
| 67 | ;
|
| 68 | }
|
| 69 |
|
| 70 | const is = typeof Object.is === "function" ? Object.is : isPolyfill;
|
| 71 |
|
| 72 |
|
| 73 | const {
|
| 74 | useState,
|
| 75 | useEffect,
|
| 76 | useLayoutEffect,
|
| 77 | useDebugValue
|
| 78 | } = React__namespace;
|
| 79 | let didWarnOld18Alpha = false;
|
| 80 | let didWarnUncachedGetSnapshot = false;
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 | function useSyncExternalStore$2(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
| 92 | // React do not expose a way to check if we're hydrating. So users of the shim
|
| 93 |
|
| 94 |
|
| 95 | getServerSnapshot) {
|
| 96 | {
|
| 97 | if (!didWarnOld18Alpha) {
|
| 98 | if ("startTransition" in React__namespace) {
|
| 99 | didWarnOld18Alpha = true;
|
| 100 | console.error("You are using an outdated, pre-release alpha of React 18 that " + "does not support useSyncExternalStore. The " + "use-sync-external-store shim will not work correctly. Upgrade " + "to a newer pre-release.");
|
| 101 | }
|
| 102 | }
|
| 103 | }
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 | const value = getSnapshot();
|
| 110 |
|
| 111 | {
|
| 112 | if (!didWarnUncachedGetSnapshot) {
|
| 113 | const cachedValue = getSnapshot();
|
| 114 |
|
| 115 | if (!is(value, cachedValue)) {
|
| 116 | console.error("The result of getSnapshot should be cached to avoid an infinite loop");
|
| 117 | didWarnUncachedGetSnapshot = true;
|
| 118 | }
|
| 119 | }
|
| 120 | }
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 | const [{
|
| 137 | inst
|
| 138 | }, forceUpdate] = useState({
|
| 139 | inst: {
|
| 140 | value,
|
| 141 | getSnapshot
|
| 142 | }
|
| 143 | });
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 | useLayoutEffect(() => {
|
| 148 | inst.value = value;
|
| 149 | inst.getSnapshot = getSnapshot;
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 | if (checkIfSnapshotChanged(inst)) {
|
| 155 |
|
| 156 | forceUpdate({
|
| 157 | inst
|
| 158 | });
|
| 159 | }
|
| 160 |
|
| 161 | }, [subscribe, value, getSnapshot]);
|
| 162 | useEffect(() => {
|
| 163 |
|
| 164 |
|
| 165 | if (checkIfSnapshotChanged(inst)) {
|
| 166 |
|
| 167 | forceUpdate({
|
| 168 | inst
|
| 169 | });
|
| 170 | }
|
| 171 |
|
| 172 | const handleStoreChange = () => {
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 | if (checkIfSnapshotChanged(inst)) {
|
| 180 |
|
| 181 | forceUpdate({
|
| 182 | inst
|
| 183 | });
|
| 184 | }
|
| 185 | };
|
| 186 |
|
| 187 |
|
| 188 | return subscribe(handleStoreChange);
|
| 189 | }, [subscribe]);
|
| 190 | useDebugValue(value);
|
| 191 | return value;
|
| 192 | }
|
| 193 |
|
| 194 | function checkIfSnapshotChanged(inst) {
|
| 195 | const latestGetSnapshot = inst.getSnapshot;
|
| 196 | const prevValue = inst.value;
|
| 197 |
|
| 198 | try {
|
| 199 | const nextValue = latestGetSnapshot();
|
| 200 | return !is(prevValue, nextValue);
|
| 201 | } catch (error) {
|
| 202 | return true;
|
| 203 | }
|
| 204 | }
|
| 205 |
|
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 |
|
| 214 | function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 | return getSnapshot();
|
| 220 | }
|
| 221 |
|
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 |
|
| 227 | const canUseDOM = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
|
| 228 | const isServerEnvironment = !canUseDOM;
|
| 229 | const shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore$2;
|
| 230 | const useSyncExternalStore = "useSyncExternalStore" in React__namespace ? (module => module.useSyncExternalStore)(React__namespace) : shim;
|
| 231 |
|
| 232 |
|
| 233 | const DataStaticRouterContext = React__namespace.createContext(null);
|
| 234 |
|
| 235 | {
|
| 236 | DataStaticRouterContext.displayName = "DataStaticRouterContext";
|
| 237 | }
|
| 238 |
|
| 239 | const DataRouterContext = React__namespace.createContext(null);
|
| 240 |
|
| 241 | {
|
| 242 | DataRouterContext.displayName = "DataRouter";
|
| 243 | }
|
| 244 |
|
| 245 | const DataRouterStateContext = React__namespace.createContext(null);
|
| 246 |
|
| 247 | {
|
| 248 | DataRouterStateContext.displayName = "DataRouterState";
|
| 249 | }
|
| 250 |
|
| 251 | const AwaitContext = React__namespace.createContext(null);
|
| 252 |
|
| 253 | {
|
| 254 | AwaitContext.displayName = "Await";
|
| 255 | }
|
| 256 |
|
| 257 | const NavigationContext = React__namespace.createContext(null);
|
| 258 |
|
| 259 | {
|
| 260 | NavigationContext.displayName = "Navigation";
|
| 261 | }
|
| 262 |
|
| 263 | const LocationContext = React__namespace.createContext(null);
|
| 264 |
|
| 265 | {
|
| 266 | LocationContext.displayName = "Location";
|
| 267 | }
|
| 268 |
|
| 269 | const RouteContext = React__namespace.createContext({
|
| 270 | outlet: null,
|
| 271 | matches: []
|
| 272 | });
|
| 273 |
|
| 274 | {
|
| 275 | RouteContext.displayName = "Route";
|
| 276 | }
|
| 277 |
|
| 278 | const RouteErrorContext = React__namespace.createContext(null);
|
| 279 |
|
| 280 | {
|
| 281 | RouteErrorContext.displayName = "RouteError";
|
| 282 | }
|
| 283 |
|
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 |
|
| 290 |
|
| 291 | function useHref(to, _temp) {
|
| 292 | let {
|
| 293 | relative
|
| 294 | } = _temp === void 0 ? {} : _temp;
|
| 295 | !useInRouterContext() ? router.invariant(false,
|
| 296 |
|
| 297 | "useHref() may be used only in the context of a <Router> component.") : void 0;
|
| 298 | let {
|
| 299 | basename,
|
| 300 | navigator
|
| 301 | } = React__namespace.useContext(NavigationContext);
|
| 302 | let {
|
| 303 | hash,
|
| 304 | pathname,
|
| 305 | search
|
| 306 | } = useResolvedPath(to, {
|
| 307 | relative
|
| 308 | });
|
| 309 | let joinedPathname = pathname;
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 | if (basename !== "/") {
|
| 315 | joinedPathname = pathname === "/" ? basename : router.joinPaths([basename, pathname]);
|
| 316 | }
|
| 317 |
|
| 318 | return navigator.createHref({
|
| 319 | pathname: joinedPathname,
|
| 320 | search,
|
| 321 | hash
|
| 322 | });
|
| 323 | }
|
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 |
|
| 329 |
|
| 330 | function useInRouterContext() {
|
| 331 | return React__namespace.useContext(LocationContext) != null;
|
| 332 | }
|
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 |
|
| 343 |
|
| 344 | function useLocation() {
|
| 345 | !useInRouterContext() ? router.invariant(false,
|
| 346 |
|
| 347 | "useLocation() may be used only in the context of a <Router> component.") : void 0;
|
| 348 | return React__namespace.useContext(LocationContext).location;
|
| 349 | }
|
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 |
|
| 356 |
|
| 357 | function useNavigationType() {
|
| 358 | return React__namespace.useContext(LocationContext).navigationType;
|
| 359 | }
|
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 |
|
| 367 |
|
| 368 | function useMatch(pattern) {
|
| 369 | !useInRouterContext() ? router.invariant(false,
|
| 370 |
|
| 371 | "useMatch() may be used only in the context of a <Router> component.") : void 0;
|
| 372 | let {
|
| 373 | pathname
|
| 374 | } = useLocation();
|
| 375 | return React__namespace.useMemo(() => router.matchPath(pattern, pathname), [pathname, pattern]);
|
| 376 | }
|
| 377 | |
| 378 | |
| 379 |
|
| 380 |
|
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 |
|
| 387 | function useNavigate() {
|
| 388 | !useInRouterContext() ? router.invariant(false,
|
| 389 |
|
| 390 | "useNavigate() may be used only in the context of a <Router> component.") : void 0;
|
| 391 | let {
|
| 392 | basename,
|
| 393 | navigator
|
| 394 | } = React__namespace.useContext(NavigationContext);
|
| 395 | let {
|
| 396 | matches
|
| 397 | } = React__namespace.useContext(RouteContext);
|
| 398 | let {
|
| 399 | pathname: locationPathname
|
| 400 | } = useLocation();
|
| 401 | let routePathnamesJson = JSON.stringify(router.UNSAFE_getPathContributingMatches(matches).map(match => match.pathnameBase));
|
| 402 | let activeRef = React__namespace.useRef(false);
|
| 403 | React__namespace.useEffect(() => {
|
| 404 | activeRef.current = true;
|
| 405 | });
|
| 406 | let navigate = React__namespace.useCallback(function (to, options) {
|
| 407 | if (options === void 0) {
|
| 408 | options = {};
|
| 409 | }
|
| 410 |
|
| 411 | router.warning(activeRef.current, "You should call navigate() in a React.useEffect(), not when " + "your component is first rendered.") ;
|
| 412 | if (!activeRef.current) return;
|
| 413 |
|
| 414 | if (typeof to === "number") {
|
| 415 | navigator.go(to);
|
| 416 | return;
|
| 417 | }
|
| 418 |
|
| 419 | let path = router.resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, options.relative === "path");
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 | if (basename !== "/") {
|
| 425 | path.pathname = path.pathname === "/" ? basename : router.joinPaths([basename, path.pathname]);
|
| 426 | }
|
| 427 |
|
| 428 | (!!options.replace ? navigator.replace : navigator.push)(path, options.state, options);
|
| 429 | }, [basename, navigator, routePathnamesJson, locationPathname]);
|
| 430 | return navigate;
|
| 431 | }
|
| 432 | const OutletContext = React__namespace.createContext(null);
|
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 |
|
| 438 |
|
| 439 | function useOutletContext() {
|
| 440 | return React__namespace.useContext(OutletContext);
|
| 441 | }
|
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 |
|
| 448 |
|
| 449 | function useOutlet(context) {
|
| 450 | let outlet = React__namespace.useContext(RouteContext).outlet;
|
| 451 |
|
| 452 | if (outlet) {
|
| 453 | return React__namespace.createElement(OutletContext.Provider, {
|
| 454 | value: context
|
| 455 | }, outlet);
|
| 456 | }
|
| 457 |
|
| 458 | return outlet;
|
| 459 | }
|
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 |
|
| 466 |
|
| 467 | function useParams() {
|
| 468 | let {
|
| 469 | matches
|
| 470 | } = React__namespace.useContext(RouteContext);
|
| 471 | let routeMatch = matches[matches.length - 1];
|
| 472 | return routeMatch ? routeMatch.params : {};
|
| 473 | }
|
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 |
|
| 479 |
|
| 480 | function useResolvedPath(to, _temp2) {
|
| 481 | let {
|
| 482 | relative
|
| 483 | } = _temp2 === void 0 ? {} : _temp2;
|
| 484 | let {
|
| 485 | matches
|
| 486 | } = React__namespace.useContext(RouteContext);
|
| 487 | let {
|
| 488 | pathname: locationPathname
|
| 489 | } = useLocation();
|
| 490 | let routePathnamesJson = JSON.stringify(router.UNSAFE_getPathContributingMatches(matches).map(match => match.pathnameBase));
|
| 491 | return React__namespace.useMemo(() => router.resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, relative === "path"), [to, routePathnamesJson, locationPathname, relative]);
|
| 492 | }
|
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 |
|
| 501 |
|
| 502 | function useRoutes(routes, locationArg) {
|
| 503 | !useInRouterContext() ? router.invariant(false,
|
| 504 |
|
| 505 | "useRoutes() may be used only in the context of a <Router> component.") : void 0;
|
| 506 | let {
|
| 507 | navigator
|
| 508 | } = React__namespace.useContext(NavigationContext);
|
| 509 | let dataRouterStateContext = React__namespace.useContext(DataRouterStateContext);
|
| 510 | let {
|
| 511 | matches: parentMatches
|
| 512 | } = React__namespace.useContext(RouteContext);
|
| 513 | let routeMatch = parentMatches[parentMatches.length - 1];
|
| 514 | let parentParams = routeMatch ? routeMatch.params : {};
|
| 515 | let parentPathname = routeMatch ? routeMatch.pathname : "/";
|
| 516 | let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
|
| 517 | let parentRoute = routeMatch && routeMatch.route;
|
| 518 |
|
| 519 | {
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 | let parentPath = parentRoute && parentRoute.path || "";
|
| 541 | 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 + "/*") + "\">."));
|
| 542 | }
|
| 543 |
|
| 544 | let locationFromContext = useLocation();
|
| 545 | let location;
|
| 546 |
|
| 547 | if (locationArg) {
|
| 548 | var _parsedLocationArg$pa;
|
| 549 |
|
| 550 | let parsedLocationArg = typeof locationArg === "string" ? router.parsePath(locationArg) : locationArg;
|
| 551 | !(parentPathnameBase === "/" || ((_parsedLocationArg$pa = parsedLocationArg.pathname) == null ? void 0 : _parsedLocationArg$pa.startsWith(parentPathnameBase))) ? router.invariant(false, "When overriding the location using `<Routes location>` or `useRoutes(routes, location)`, " + "the location pathname must begin with the portion of the URL pathname that was " + ("matched by all parent routes. The current pathname base is \"" + parentPathnameBase + "\" ") + ("but pathname \"" + parsedLocationArg.pathname + "\" was given in the `location` prop.")) : void 0;
|
| 552 | location = parsedLocationArg;
|
| 553 | } else {
|
| 554 | location = locationFromContext;
|
| 555 | }
|
| 556 |
|
| 557 | let pathname = location.pathname || "/";
|
| 558 | let remainingPathname = parentPathnameBase === "/" ? pathname : pathname.slice(parentPathnameBase.length) || "/";
|
| 559 | let matches = router.matchRoutes(routes, {
|
| 560 | pathname: remainingPathname
|
| 561 | });
|
| 562 |
|
| 563 | {
|
| 564 | router.warning(parentRoute || matches != null, "No routes matched location \"" + location.pathname + location.search + location.hash + "\" ") ;
|
| 565 | router.warning(matches == null || matches[matches.length - 1].route.element !== undefined, "Matched leaf route at location \"" + location.pathname + location.search + location.hash + "\" does not have an element. " + "This means it will render an <Outlet /> with a null value by default resulting in an \"empty\" page.") ;
|
| 566 | }
|
| 567 |
|
| 568 | let renderedMatches = _renderMatches(matches && matches.map(match => Object.assign({}, match, {
|
| 569 | params: Object.assign({}, parentParams, match.params),
|
| 570 | pathname: router.joinPaths([parentPathnameBase,
|
| 571 | navigator.encodeLocation ? navigator.encodeLocation(match.pathname).pathname : match.pathname]),
|
| 572 | pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : router.joinPaths([parentPathnameBase,
|
| 573 | navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase).pathname : match.pathnameBase])
|
| 574 | })), parentMatches, dataRouterStateContext || undefined);
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 | if (locationArg && renderedMatches) {
|
| 580 | return React__namespace.createElement(LocationContext.Provider, {
|
| 581 | value: {
|
| 582 | location: _extends({
|
| 583 | pathname: "/",
|
| 584 | search: "",
|
| 585 | hash: "",
|
| 586 | state: null,
|
| 587 | key: "default"
|
| 588 | }, location),
|
| 589 | navigationType: router.Action.Pop
|
| 590 | }
|
| 591 | }, renderedMatches);
|
| 592 | }
|
| 593 |
|
| 594 | return renderedMatches;
|
| 595 | }
|
| 596 |
|
| 597 | function DefaultErrorElement() {
|
| 598 | let error = useRouteError();
|
| 599 | let message = router.isRouteErrorResponse(error) ? error.status + " " + error.statusText : error instanceof Error ? error.message : JSON.stringify(error);
|
| 600 | let stack = error instanceof Error ? error.stack : null;
|
| 601 | let lightgrey = "rgba(200,200,200, 0.5)";
|
| 602 | let preStyles = {
|
| 603 | padding: "0.5rem",
|
| 604 | backgroundColor: lightgrey
|
| 605 | };
|
| 606 | let codeStyles = {
|
| 607 | padding: "2px 4px",
|
| 608 | backgroundColor: lightgrey
|
| 609 | };
|
| 610 | return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement("h2", null, "Unhandled Thrown Error!"), React__namespace.createElement("h3", {
|
| 611 | style: {
|
| 612 | fontStyle: "italic"
|
| 613 | }
|
| 614 | }, message), stack ? React__namespace.createElement("pre", {
|
| 615 | style: preStyles
|
| 616 | }, stack) : null, React__namespace.createElement("p", null, "\uD83D\uDCBF Hey developer \uD83D\uDC4B"), React__namespace.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own\xA0", React__namespace.createElement("code", {
|
| 617 | style: codeStyles
|
| 618 | }, "errorElement"), " props on\xA0", React__namespace.createElement("code", {
|
| 619 | style: codeStyles
|
| 620 | }, "<Route>")));
|
| 621 | }
|
| 622 |
|
| 623 | class RenderErrorBoundary extends React__namespace.Component {
|
| 624 | constructor(props) {
|
| 625 | super(props);
|
| 626 | this.state = {
|
| 627 | location: props.location,
|
| 628 | error: props.error
|
| 629 | };
|
| 630 | }
|
| 631 |
|
| 632 | static getDerivedStateFromError(error) {
|
| 633 | return {
|
| 634 | error: error
|
| 635 | };
|
| 636 | }
|
| 637 |
|
| 638 | static getDerivedStateFromProps(props, state) {
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 | if (state.location !== props.location) {
|
| 648 | return {
|
| 649 | error: props.error,
|
| 650 | location: props.location
|
| 651 | };
|
| 652 | }
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 | return {
|
| 659 | error: props.error || state.error,
|
| 660 | location: state.location
|
| 661 | };
|
| 662 | }
|
| 663 |
|
| 664 | componentDidCatch(error, errorInfo) {
|
| 665 | console.error("React Router caught the following error during render", error, errorInfo);
|
| 666 | }
|
| 667 |
|
| 668 | render() {
|
| 669 | return this.state.error ? React__namespace.createElement(RouteErrorContext.Provider, {
|
| 670 | value: this.state.error,
|
| 671 | children: this.props.component
|
| 672 | }) : this.props.children;
|
| 673 | }
|
| 674 |
|
| 675 | }
|
| 676 |
|
| 677 | function RenderedRoute(_ref) {
|
| 678 | let {
|
| 679 | routeContext,
|
| 680 | match,
|
| 681 | children
|
| 682 | } = _ref;
|
| 683 | let dataStaticRouterContext = React__namespace.useContext(DataStaticRouterContext);
|
| 684 |
|
| 685 |
|
| 686 | if (dataStaticRouterContext && match.route.errorElement) {
|
| 687 | dataStaticRouterContext._deepestRenderedBoundaryId = match.route.id;
|
| 688 | }
|
| 689 |
|
| 690 | return React__namespace.createElement(RouteContext.Provider, {
|
| 691 | value: routeContext
|
| 692 | }, children);
|
| 693 | }
|
| 694 |
|
| 695 | function _renderMatches(matches, parentMatches, dataRouterState) {
|
| 696 | if (parentMatches === void 0) {
|
| 697 | parentMatches = [];
|
| 698 | }
|
| 699 |
|
| 700 | if (matches == null) {
|
| 701 | if (dataRouterState != null && dataRouterState.errors) {
|
| 702 |
|
| 703 |
|
| 704 | matches = dataRouterState.matches;
|
| 705 | } else {
|
| 706 | return null;
|
| 707 | }
|
| 708 | }
|
| 709 |
|
| 710 | let renderedMatches = matches;
|
| 711 |
|
| 712 | let errors = dataRouterState == null ? void 0 : dataRouterState.errors;
|
| 713 |
|
| 714 | if (errors != null) {
|
| 715 | let errorIndex = renderedMatches.findIndex(m => m.route.id && (errors == null ? void 0 : errors[m.route.id]));
|
| 716 | !(errorIndex >= 0) ? router.invariant(false, "Could not find a matching route for the current errors: " + errors) : void 0;
|
| 717 | renderedMatches = renderedMatches.slice(0, Math.min(renderedMatches.length, errorIndex + 1));
|
| 718 | }
|
| 719 |
|
| 720 | return renderedMatches.reduceRight((outlet, match, index) => {
|
| 721 | let error = match.route.id ? errors == null ? void 0 : errors[match.route.id] : null;
|
| 722 |
|
| 723 | let errorElement = dataRouterState ? match.route.errorElement || React__namespace.createElement(DefaultErrorElement, null) : null;
|
| 724 |
|
| 725 | let getChildren = () => React__namespace.createElement(RenderedRoute, {
|
| 726 | match: match,
|
| 727 | routeContext: {
|
| 728 | outlet,
|
| 729 | matches: parentMatches.concat(renderedMatches.slice(0, index + 1))
|
| 730 | }
|
| 731 | }, error ? errorElement : match.route.element !== undefined ? match.route.element : outlet);
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 | return dataRouterState && (match.route.errorElement || index === 0) ? React__namespace.createElement(RenderErrorBoundary, {
|
| 737 | location: dataRouterState.location,
|
| 738 | component: errorElement,
|
| 739 | error: error,
|
| 740 | children: getChildren()
|
| 741 | }) : getChildren();
|
| 742 | }, null);
|
| 743 | }
|
| 744 | var DataRouterHook;
|
| 745 |
|
| 746 | (function (DataRouterHook) {
|
| 747 | DataRouterHook["UseRevalidator"] = "useRevalidator";
|
| 748 | })(DataRouterHook || (DataRouterHook = {}));
|
| 749 |
|
| 750 | var DataRouterStateHook;
|
| 751 |
|
| 752 | (function (DataRouterStateHook) {
|
| 753 | DataRouterStateHook["UseLoaderData"] = "useLoaderData";
|
| 754 | DataRouterStateHook["UseActionData"] = "useActionData";
|
| 755 | DataRouterStateHook["UseRouteError"] = "useRouteError";
|
| 756 | DataRouterStateHook["UseNavigation"] = "useNavigation";
|
| 757 | DataRouterStateHook["UseRouteLoaderData"] = "useRouteLoaderData";
|
| 758 | DataRouterStateHook["UseMatches"] = "useMatches";
|
| 759 | DataRouterStateHook["UseRevalidator"] = "useRevalidator";
|
| 760 | })(DataRouterStateHook || (DataRouterStateHook = {}));
|
| 761 |
|
| 762 | function getDataRouterConsoleError(hookName) {
|
| 763 | return hookName + " must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.";
|
| 764 | }
|
| 765 |
|
| 766 | function useDataRouterContext(hookName) {
|
| 767 | let ctx = React__namespace.useContext(DataRouterContext);
|
| 768 | !ctx ? router.invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
| 769 | return ctx;
|
| 770 | }
|
| 771 |
|
| 772 | function useDataRouterState(hookName) {
|
| 773 | let state = React__namespace.useContext(DataRouterStateContext);
|
| 774 | !state ? router.invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
| 775 | return state;
|
| 776 | }
|
| 777 | |
| 778 | |
| 779 | |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 | function useNavigation() {
|
| 784 | let state = useDataRouterState(DataRouterStateHook.UseNavigation);
|
| 785 | return state.navigation;
|
| 786 | }
|
| 787 | |
| 788 | |
| 789 | |
| 790 |
|
| 791 |
|
| 792 | function useRevalidator() {
|
| 793 | let dataRouterContext = useDataRouterContext(DataRouterHook.UseRevalidator);
|
| 794 | let state = useDataRouterState(DataRouterStateHook.UseRevalidator);
|
| 795 | return {
|
| 796 | revalidate: dataRouterContext.router.revalidate,
|
| 797 | state: state.revalidation
|
| 798 | };
|
| 799 | }
|
| 800 | |
| 801 | |
| 802 | |
| 803 |
|
| 804 |
|
| 805 | function useMatches() {
|
| 806 | let {
|
| 807 | matches,
|
| 808 | loaderData
|
| 809 | } = useDataRouterState(DataRouterStateHook.UseMatches);
|
| 810 | return React__namespace.useMemo(() => matches.map(match => {
|
| 811 | let {
|
| 812 | pathname,
|
| 813 | params
|
| 814 | } = match;
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 | return {
|
| 819 | id: match.route.id,
|
| 820 | pathname,
|
| 821 | params,
|
| 822 | data: loaderData[match.route.id],
|
| 823 | handle: match.route.handle
|
| 824 | };
|
| 825 | }), [matches, loaderData]);
|
| 826 | }
|
| 827 | |
| 828 | |
| 829 |
|
| 830 |
|
| 831 | function useLoaderData() {
|
| 832 | let state = useDataRouterState(DataRouterStateHook.UseLoaderData);
|
| 833 | let route = React__namespace.useContext(RouteContext);
|
| 834 | !route ? router.invariant(false, "useLoaderData must be used inside a RouteContext") : void 0;
|
| 835 | let thisRoute = route.matches[route.matches.length - 1];
|
| 836 | !thisRoute.route.id ? router.invariant(false, "useLoaderData can only be used on routes that contain a unique \"id\"") : void 0;
|
| 837 | return state.loaderData[thisRoute.route.id];
|
| 838 | }
|
| 839 | |
| 840 | |
| 841 |
|
| 842 |
|
| 843 | function useRouteLoaderData(routeId) {
|
| 844 | let state = useDataRouterState(DataRouterStateHook.UseRouteLoaderData);
|
| 845 | return state.loaderData[routeId];
|
| 846 | }
|
| 847 | |
| 848 | |
| 849 |
|
| 850 |
|
| 851 | function useActionData() {
|
| 852 | let state = useDataRouterState(DataRouterStateHook.UseActionData);
|
| 853 | let route = React__namespace.useContext(RouteContext);
|
| 854 | !route ? router.invariant(false, "useActionData must be used inside a RouteContext") : void 0;
|
| 855 | return Object.values((state == null ? void 0 : state.actionData) || {})[0];
|
| 856 | }
|
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 |
|
| 862 |
|
| 863 | function useRouteError() {
|
| 864 | var _state$errors;
|
| 865 |
|
| 866 | let error = React__namespace.useContext(RouteErrorContext);
|
| 867 | let state = useDataRouterState(DataRouterStateHook.UseRouteError);
|
| 868 | let route = React__namespace.useContext(RouteContext);
|
| 869 | let thisRoute = route.matches[route.matches.length - 1];
|
| 870 |
|
| 871 |
|
| 872 | if (error) {
|
| 873 | return error;
|
| 874 | }
|
| 875 |
|
| 876 | !route ? router.invariant(false, "useRouteError must be used inside a RouteContext") : void 0;
|
| 877 | !thisRoute.route.id ? router.invariant(false, "useRouteError can only be used on routes that contain a unique \"id\"") : void 0;
|
| 878 |
|
| 879 | return (_state$errors = state.errors) == null ? void 0 : _state$errors[thisRoute.route.id];
|
| 880 | }
|
| 881 | |
| 882 | |
| 883 |
|
| 884 |
|
| 885 | function useAsyncValue() {
|
| 886 | let value = React__namespace.useContext(AwaitContext);
|
| 887 | return value == null ? void 0 : value._data;
|
| 888 | }
|
| 889 | |
| 890 | |
| 891 |
|
| 892 |
|
| 893 | function useAsyncError() {
|
| 894 | let value = React__namespace.useContext(AwaitContext);
|
| 895 | return value == null ? void 0 : value._error;
|
| 896 | }
|
| 897 | const alreadyWarned = {};
|
| 898 |
|
| 899 | function warningOnce(key, cond, message) {
|
| 900 | if (!cond && !alreadyWarned[key]) {
|
| 901 | alreadyWarned[key] = true;
|
| 902 | router.warning(false, message) ;
|
| 903 | }
|
| 904 | }
|
| 905 |
|
| 906 | |
| 907 | |
| 908 |
|
| 909 | function RouterProvider(_ref) {
|
| 910 | let {
|
| 911 | fallbackElement,
|
| 912 | router
|
| 913 | } = _ref;
|
| 914 |
|
| 915 | let state = useSyncExternalStore(router.subscribe, () => router.state,
|
| 916 |
|
| 917 |
|
| 918 | () => router.state);
|
| 919 | let navigator = React__namespace.useMemo(() => {
|
| 920 | return {
|
| 921 | createHref: router.createHref,
|
| 922 | encodeLocation: router.encodeLocation,
|
| 923 | go: n => router.navigate(n),
|
| 924 | push: (to, state, opts) => router.navigate(to, {
|
| 925 | state,
|
| 926 | preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
|
| 927 | }),
|
| 928 | replace: (to, state, opts) => router.navigate(to, {
|
| 929 | replace: true,
|
| 930 | state,
|
| 931 | preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
|
| 932 | })
|
| 933 | };
|
| 934 | }, [router]);
|
| 935 | let basename = router.basename || "/";
|
| 936 | return React__namespace.createElement(DataRouterContext.Provider, {
|
| 937 | value: {
|
| 938 | router,
|
| 939 | navigator,
|
| 940 | static: false,
|
| 941 |
|
| 942 | basename
|
| 943 | }
|
| 944 | }, React__namespace.createElement(DataRouterStateContext.Provider, {
|
| 945 | value: state
|
| 946 | }, React__namespace.createElement(Router, {
|
| 947 | basename: router.basename,
|
| 948 | location: router.state.location,
|
| 949 | navigationType: router.state.historyAction,
|
| 950 | navigator: navigator
|
| 951 | }, router.state.initialized ? React__namespace.createElement(Routes, null) : fallbackElement)));
|
| 952 | }
|
| 953 |
|
| 954 | |
| 955 | |
| 956 | |
| 957 | |
| 958 |
|
| 959 | function MemoryRouter(_ref2) {
|
| 960 | let {
|
| 961 | basename,
|
| 962 | children,
|
| 963 | initialEntries,
|
| 964 | initialIndex
|
| 965 | } = _ref2;
|
| 966 | let historyRef = React__namespace.useRef();
|
| 967 |
|
| 968 | if (historyRef.current == null) {
|
| 969 | historyRef.current = router.createMemoryHistory({
|
| 970 | initialEntries,
|
| 971 | initialIndex,
|
| 972 | v5Compat: true
|
| 973 | });
|
| 974 | }
|
| 975 |
|
| 976 | let history = historyRef.current;
|
| 977 | let [state, setState] = React__namespace.useState({
|
| 978 | action: history.action,
|
| 979 | location: history.location
|
| 980 | });
|
| 981 | React__namespace.useLayoutEffect(() => history.listen(setState), [history]);
|
| 982 | return React__namespace.createElement(Router, {
|
| 983 | basename: basename,
|
| 984 | children: children,
|
| 985 | location: state.location,
|
| 986 | navigationType: state.action,
|
| 987 | navigator: history
|
| 988 | });
|
| 989 | }
|
| 990 |
|
| 991 | |
| 992 | |
| 993 | |
| 994 | |
| 995 | |
| 996 | |
| 997 | |
| 998 | |
| 999 |
|
| 1000 | function Navigate(_ref3) {
|
| 1001 | let {
|
| 1002 | to,
|
| 1003 | replace,
|
| 1004 | state,
|
| 1005 | relative
|
| 1006 | } = _ref3;
|
| 1007 | !useInRouterContext() ? router.invariant(false,
|
| 1008 |
|
| 1009 | "<Navigate> may be used only in the context of a <Router> component.") : void 0;
|
| 1010 | router.warning(!React__namespace.useContext(NavigationContext).static, "<Navigate> must not be used on the initial render in a <StaticRouter>. " + "This is a no-op, but you should modify your code so the <Navigate> is " + "only ever rendered in response to some user interaction or state change.") ;
|
| 1011 | let dataRouterState = React__namespace.useContext(DataRouterStateContext);
|
| 1012 | let navigate = useNavigate();
|
| 1013 | React__namespace.useEffect(() => {
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 | if (dataRouterState && dataRouterState.navigation.state !== "idle") {
|
| 1018 | return;
|
| 1019 | }
|
| 1020 |
|
| 1021 | navigate(to, {
|
| 1022 | replace,
|
| 1023 | state,
|
| 1024 | relative
|
| 1025 | });
|
| 1026 | });
|
| 1027 | return null;
|
| 1028 | }
|
| 1029 |
|
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 |
|
| 1035 | function Outlet(props) {
|
| 1036 | return useOutlet(props.context);
|
| 1037 | }
|
| 1038 |
|
| 1039 | |
| 1040 | |
| 1041 | |
| 1042 | |
| 1043 |
|
| 1044 | function Route(_props) {
|
| 1045 | router.invariant(false, "A <Route> is only ever to be used as the child of <Routes> element, " + "never rendered directly. Please wrap your <Route> in a <Routes>.") ;
|
| 1046 | }
|
| 1047 |
|
| 1048 | |
| 1049 | |
| 1050 | |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | |
| 1055 | |
| 1056 |
|
| 1057 | function Router(_ref4) {
|
| 1058 | let {
|
| 1059 | basename: basenameProp = "/",
|
| 1060 | children = null,
|
| 1061 | location: locationProp,
|
| 1062 | navigationType = router.Action.Pop,
|
| 1063 | navigator,
|
| 1064 | static: staticProp = false
|
| 1065 | } = _ref4;
|
| 1066 | !!useInRouterContext() ? router.invariant(false, "You cannot render a <Router> inside another <Router>." + " You should never have more than one in your app.") : void 0;
|
| 1067 |
|
| 1068 |
|
| 1069 | let basename = basenameProp.replace(/^\/*/, "/");
|
| 1070 | let navigationContext = React__namespace.useMemo(() => ({
|
| 1071 | basename,
|
| 1072 | navigator,
|
| 1073 | static: staticProp
|
| 1074 | }), [basename, navigator, staticProp]);
|
| 1075 |
|
| 1076 | if (typeof locationProp === "string") {
|
| 1077 | locationProp = router.parsePath(locationProp);
|
| 1078 | }
|
| 1079 |
|
| 1080 | let {
|
| 1081 | pathname = "/",
|
| 1082 | search = "",
|
| 1083 | hash = "",
|
| 1084 | state = null,
|
| 1085 | key = "default"
|
| 1086 | } = locationProp;
|
| 1087 | let location = React__namespace.useMemo(() => {
|
| 1088 | let trailingPathname = router.stripBasename(pathname, basename);
|
| 1089 |
|
| 1090 | if (trailingPathname == null) {
|
| 1091 | return null;
|
| 1092 | }
|
| 1093 |
|
| 1094 | return {
|
| 1095 | pathname: trailingPathname,
|
| 1096 | search,
|
| 1097 | hash,
|
| 1098 | state,
|
| 1099 | key
|
| 1100 | };
|
| 1101 | }, [basename, pathname, search, hash, state, key]);
|
| 1102 | router.warning(location != null, "<Router basename=\"" + basename + "\"> is not able to match the URL " + ("\"" + pathname + search + hash + "\" because it does not start with the ") + "basename, so the <Router> won't render anything.") ;
|
| 1103 |
|
| 1104 | if (location == null) {
|
| 1105 | return null;
|
| 1106 | }
|
| 1107 |
|
| 1108 | return React__namespace.createElement(NavigationContext.Provider, {
|
| 1109 | value: navigationContext
|
| 1110 | }, React__namespace.createElement(LocationContext.Provider, {
|
| 1111 | children: children,
|
| 1112 | value: {
|
| 1113 | location,
|
| 1114 | navigationType
|
| 1115 | }
|
| 1116 | }));
|
| 1117 | }
|
| 1118 |
|
| 1119 | |
| 1120 | |
| 1121 | |
| 1122 | |
| 1123 | |
| 1124 |
|
| 1125 | function Routes(_ref5) {
|
| 1126 | let {
|
| 1127 | children,
|
| 1128 | location
|
| 1129 | } = _ref5;
|
| 1130 | let dataRouterContext = React__namespace.useContext(DataRouterContext);
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 | let routes = dataRouterContext && !children ? dataRouterContext.router.routes : createRoutesFromChildren(children);
|
| 1135 | return useRoutes(routes, location);
|
| 1136 | }
|
| 1137 |
|
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 |
|
| 1142 | function Await(_ref6) {
|
| 1143 | let {
|
| 1144 | children,
|
| 1145 | errorElement,
|
| 1146 | resolve
|
| 1147 | } = _ref6;
|
| 1148 | return React__namespace.createElement(AwaitErrorBoundary, {
|
| 1149 | resolve: resolve,
|
| 1150 | errorElement: errorElement
|
| 1151 | }, React__namespace.createElement(ResolveAwait, null, children));
|
| 1152 | }
|
| 1153 | var AwaitRenderStatus;
|
| 1154 |
|
| 1155 | (function (AwaitRenderStatus) {
|
| 1156 | AwaitRenderStatus[AwaitRenderStatus["pending"] = 0] = "pending";
|
| 1157 | AwaitRenderStatus[AwaitRenderStatus["success"] = 1] = "success";
|
| 1158 | AwaitRenderStatus[AwaitRenderStatus["error"] = 2] = "error";
|
| 1159 | })(AwaitRenderStatus || (AwaitRenderStatus = {}));
|
| 1160 |
|
| 1161 | const neverSettledPromise = new Promise(() => {});
|
| 1162 |
|
| 1163 | class AwaitErrorBoundary extends React__namespace.Component {
|
| 1164 | constructor(props) {
|
| 1165 | super(props);
|
| 1166 | this.state = {
|
| 1167 | error: null
|
| 1168 | };
|
| 1169 | }
|
| 1170 |
|
| 1171 | static getDerivedStateFromError(error) {
|
| 1172 | return {
|
| 1173 | error
|
| 1174 | };
|
| 1175 | }
|
| 1176 |
|
| 1177 | componentDidCatch(error, errorInfo) {
|
| 1178 | console.error("<Await> caught the following error during render", error, errorInfo);
|
| 1179 | }
|
| 1180 |
|
| 1181 | render() {
|
| 1182 | let {
|
| 1183 | children,
|
| 1184 | errorElement,
|
| 1185 | resolve
|
| 1186 | } = this.props;
|
| 1187 | let promise = null;
|
| 1188 | let status = AwaitRenderStatus.pending;
|
| 1189 |
|
| 1190 | if (!(resolve instanceof Promise)) {
|
| 1191 |
|
| 1192 | status = AwaitRenderStatus.success;
|
| 1193 | promise = Promise.resolve();
|
| 1194 | Object.defineProperty(promise, "_tracked", {
|
| 1195 | get: () => true
|
| 1196 | });
|
| 1197 | Object.defineProperty(promise, "_data", {
|
| 1198 | get: () => resolve
|
| 1199 | });
|
| 1200 | } else if (this.state.error) {
|
| 1201 |
|
| 1202 | status = AwaitRenderStatus.error;
|
| 1203 | let renderError = this.state.error;
|
| 1204 | promise = Promise.reject().catch(() => {});
|
| 1205 |
|
| 1206 | Object.defineProperty(promise, "_tracked", {
|
| 1207 | get: () => true
|
| 1208 | });
|
| 1209 | Object.defineProperty(promise, "_error", {
|
| 1210 | get: () => renderError
|
| 1211 | });
|
| 1212 | } else if (resolve._tracked) {
|
| 1213 |
|
| 1214 | promise = resolve;
|
| 1215 | status = promise._error !== undefined ? AwaitRenderStatus.error : promise._data !== undefined ? AwaitRenderStatus.success : AwaitRenderStatus.pending;
|
| 1216 | } else {
|
| 1217 |
|
| 1218 | status = AwaitRenderStatus.pending;
|
| 1219 | Object.defineProperty(resolve, "_tracked", {
|
| 1220 | get: () => true
|
| 1221 | });
|
| 1222 | promise = resolve.then(data => Object.defineProperty(resolve, "_data", {
|
| 1223 | get: () => data
|
| 1224 | }), error => Object.defineProperty(resolve, "_error", {
|
| 1225 | get: () => error
|
| 1226 | }));
|
| 1227 | }
|
| 1228 |
|
| 1229 | if (status === AwaitRenderStatus.error && promise._error instanceof router.AbortedDeferredError) {
|
| 1230 |
|
| 1231 | throw neverSettledPromise;
|
| 1232 | }
|
| 1233 |
|
| 1234 | if (status === AwaitRenderStatus.error && !errorElement) {
|
| 1235 |
|
| 1236 | throw promise._error;
|
| 1237 | }
|
| 1238 |
|
| 1239 | if (status === AwaitRenderStatus.error) {
|
| 1240 |
|
| 1241 | return React__namespace.createElement(AwaitContext.Provider, {
|
| 1242 | value: promise,
|
| 1243 | children: errorElement
|
| 1244 | });
|
| 1245 | }
|
| 1246 |
|
| 1247 | if (status === AwaitRenderStatus.success) {
|
| 1248 |
|
| 1249 | return React__namespace.createElement(AwaitContext.Provider, {
|
| 1250 | value: promise,
|
| 1251 | children: children
|
| 1252 | });
|
| 1253 | }
|
| 1254 |
|
| 1255 |
|
| 1256 | throw promise;
|
| 1257 | }
|
| 1258 |
|
| 1259 | }
|
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 | function ResolveAwait(_ref7) {
|
| 1267 | let {
|
| 1268 | children
|
| 1269 | } = _ref7;
|
| 1270 | let data = useAsyncValue();
|
| 1271 |
|
| 1272 | if (typeof children === "function") {
|
| 1273 | return children(data);
|
| 1274 | }
|
| 1275 |
|
| 1276 | return React__namespace.createElement(React__namespace.Fragment, null, children);
|
| 1277 | }
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 | |
| 1282 | |
| 1283 | |
| 1284 | |
| 1285 | |
| 1286 | |
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 | function createRoutesFromChildren(children, parentPath) {
|
| 1291 | if (parentPath === void 0) {
|
| 1292 | parentPath = [];
|
| 1293 | }
|
| 1294 |
|
| 1295 | let routes = [];
|
| 1296 | React__namespace.Children.forEach(children, (element, index) => {
|
| 1297 | if (! React__namespace.isValidElement(element)) {
|
| 1298 |
|
| 1299 |
|
| 1300 | return;
|
| 1301 | }
|
| 1302 |
|
| 1303 | if (element.type === React__namespace.Fragment) {
|
| 1304 |
|
| 1305 | routes.push.apply(routes, createRoutesFromChildren(element.props.children, parentPath));
|
| 1306 | return;
|
| 1307 | }
|
| 1308 |
|
| 1309 | !(element.type === Route) ? router.invariant(false, "[" + (typeof element.type === "string" ? element.type : element.type.name) + "] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>") : void 0;
|
| 1310 | !(!element.props.index || !element.props.children) ? router.invariant(false, "An index route cannot have child routes.") : void 0;
|
| 1311 | let treePath = [...parentPath, index];
|
| 1312 | let route = {
|
| 1313 | id: element.props.id || treePath.join("-"),
|
| 1314 | caseSensitive: element.props.caseSensitive,
|
| 1315 | element: element.props.element,
|
| 1316 | index: element.props.index,
|
| 1317 | path: element.props.path,
|
| 1318 | loader: element.props.loader,
|
| 1319 | action: element.props.action,
|
| 1320 | errorElement: element.props.errorElement,
|
| 1321 | hasErrorBoundary: element.props.errorElement != null,
|
| 1322 | shouldRevalidate: element.props.shouldRevalidate,
|
| 1323 | handle: element.props.handle
|
| 1324 | };
|
| 1325 |
|
| 1326 | if (element.props.children) {
|
| 1327 | route.children = createRoutesFromChildren(element.props.children, treePath);
|
| 1328 | }
|
| 1329 |
|
| 1330 | routes.push(route);
|
| 1331 | });
|
| 1332 | return routes;
|
| 1333 | }
|
| 1334 | |
| 1335 | |
| 1336 |
|
| 1337 |
|
| 1338 | function renderMatches(matches) {
|
| 1339 | return _renderMatches(matches);
|
| 1340 | }
|
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 |
|
| 1346 |
|
| 1347 | function enhanceManualRouteObjects(routes) {
|
| 1348 | return routes.map(route => {
|
| 1349 | let routeClone = _extends({}, route);
|
| 1350 |
|
| 1351 | if (routeClone.hasErrorBoundary == null) {
|
| 1352 | routeClone.hasErrorBoundary = routeClone.errorElement != null;
|
| 1353 | }
|
| 1354 |
|
| 1355 | if (routeClone.children) {
|
| 1356 | routeClone.children = enhanceManualRouteObjects(routeClone.children);
|
| 1357 | }
|
| 1358 |
|
| 1359 | return routeClone;
|
| 1360 | });
|
| 1361 | }
|
| 1362 |
|
| 1363 | function createMemoryRouter(routes, opts) {
|
| 1364 | return router.createRouter({
|
| 1365 | basename: opts == null ? void 0 : opts.basename,
|
| 1366 | history: router.createMemoryHistory({
|
| 1367 | initialEntries: opts == null ? void 0 : opts.initialEntries,
|
| 1368 | initialIndex: opts == null ? void 0 : opts.initialIndex
|
| 1369 | }),
|
| 1370 | hydrationData: opts == null ? void 0 : opts.hydrationData,
|
| 1371 | routes: enhanceManualRouteObjects(routes)
|
| 1372 | }).initialize();
|
| 1373 | }
|
| 1374 |
|
| 1375 | Object.defineProperty(exports, 'AbortedDeferredError', {
|
| 1376 | enumerable: true,
|
| 1377 | get: function () { return router.AbortedDeferredError; }
|
| 1378 | });
|
| 1379 | Object.defineProperty(exports, 'NavigationType', {
|
| 1380 | enumerable: true,
|
| 1381 | get: function () { return router.Action; }
|
| 1382 | });
|
| 1383 | Object.defineProperty(exports, 'createPath', {
|
| 1384 | enumerable: true,
|
| 1385 | get: function () { return router.createPath; }
|
| 1386 | });
|
| 1387 | Object.defineProperty(exports, 'defer', {
|
| 1388 | enumerable: true,
|
| 1389 | get: function () { return router.defer; }
|
| 1390 | });
|
| 1391 | Object.defineProperty(exports, 'generatePath', {
|
| 1392 | enumerable: true,
|
| 1393 | get: function () { return router.generatePath; }
|
| 1394 | });
|
| 1395 | Object.defineProperty(exports, 'isRouteErrorResponse', {
|
| 1396 | enumerable: true,
|
| 1397 | get: function () { return router.isRouteErrorResponse; }
|
| 1398 | });
|
| 1399 | Object.defineProperty(exports, 'json', {
|
| 1400 | enumerable: true,
|
| 1401 | get: function () { return router.json; }
|
| 1402 | });
|
| 1403 | Object.defineProperty(exports, 'matchPath', {
|
| 1404 | enumerable: true,
|
| 1405 | get: function () { return router.matchPath; }
|
| 1406 | });
|
| 1407 | Object.defineProperty(exports, 'matchRoutes', {
|
| 1408 | enumerable: true,
|
| 1409 | get: function () { return router.matchRoutes; }
|
| 1410 | });
|
| 1411 | Object.defineProperty(exports, 'parsePath', {
|
| 1412 | enumerable: true,
|
| 1413 | get: function () { return router.parsePath; }
|
| 1414 | });
|
| 1415 | Object.defineProperty(exports, 'redirect', {
|
| 1416 | enumerable: true,
|
| 1417 | get: function () { return router.redirect; }
|
| 1418 | });
|
| 1419 | Object.defineProperty(exports, 'resolvePath', {
|
| 1420 | enumerable: true,
|
| 1421 | get: function () { return router.resolvePath; }
|
| 1422 | });
|
| 1423 | exports.Await = Await;
|
| 1424 | exports.MemoryRouter = MemoryRouter;
|
| 1425 | exports.Navigate = Navigate;
|
| 1426 | exports.Outlet = Outlet;
|
| 1427 | exports.Route = Route;
|
| 1428 | exports.Router = Router;
|
| 1429 | exports.RouterProvider = RouterProvider;
|
| 1430 | exports.Routes = Routes;
|
| 1431 | exports.UNSAFE_DataRouterContext = DataRouterContext;
|
| 1432 | exports.UNSAFE_DataRouterStateContext = DataRouterStateContext;
|
| 1433 | exports.UNSAFE_DataStaticRouterContext = DataStaticRouterContext;
|
| 1434 | exports.UNSAFE_LocationContext = LocationContext;
|
| 1435 | exports.UNSAFE_NavigationContext = NavigationContext;
|
| 1436 | exports.UNSAFE_RouteContext = RouteContext;
|
| 1437 | exports.UNSAFE_enhanceManualRouteObjects = enhanceManualRouteObjects;
|
| 1438 | exports.createMemoryRouter = createMemoryRouter;
|
| 1439 | exports.createRoutesFromChildren = createRoutesFromChildren;
|
| 1440 | exports.createRoutesFromElements = createRoutesFromChildren;
|
| 1441 | exports.renderMatches = renderMatches;
|
| 1442 | exports.useActionData = useActionData;
|
| 1443 | exports.useAsyncError = useAsyncError;
|
| 1444 | exports.useAsyncValue = useAsyncValue;
|
| 1445 | exports.useHref = useHref;
|
| 1446 | exports.useInRouterContext = useInRouterContext;
|
| 1447 | exports.useLoaderData = useLoaderData;
|
| 1448 | exports.useLocation = useLocation;
|
| 1449 | exports.useMatch = useMatch;
|
| 1450 | exports.useMatches = useMatches;
|
| 1451 | exports.useNavigate = useNavigate;
|
| 1452 | exports.useNavigation = useNavigation;
|
| 1453 | exports.useNavigationType = useNavigationType;
|
| 1454 | exports.useOutlet = useOutlet;
|
| 1455 | exports.useOutletContext = useOutletContext;
|
| 1456 | exports.useParams = useParams;
|
| 1457 | exports.useResolvedPath = useResolvedPath;
|
| 1458 | exports.useRevalidator = useRevalidator;
|
| 1459 | exports.useRouteError = useRouteError;
|
| 1460 | exports.useRouteLoaderData = useRouteLoaderData;
|
| 1461 | exports.useRoutes = useRoutes;
|
| 1462 |
|
| 1463 | Object.defineProperty(exports, '__esModule', { value: true });
|
| 1464 |
|
| 1465 | }));
|
| 1466 |
|