react-router 6.4.0-pre.6 → 6.4.0-pre.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,99 @@
1
1
  # react-router
2
2
 
3
+ ## 6.4.0-pre.9
4
+
5
+ ### Patch Changes
6
+
7
+ - Feat: adds `deferred` support to data routers (#9002)
8
+
9
+ Returning a `deferred` from a `loader` allows you to separate _critical_ loader data that you want to wait for prior to rendering the destination page from _non-critical_ data that you are OK to show a spinner for until it loads.
10
+
11
+ ```jsx
12
+ // In your route loader, return a deferred() and choose per-key whether to
13
+ // await the promise or not. As soon as the awaited promises resolve, the
14
+ // page will be rendered.
15
+ function loader() {
16
+ return deferred({
17
+ critical: await getCriticalData(),
18
+ lazy1: getLazyData(),
19
+ });
20
+ };
21
+
22
+ // In your route element, grab the values from useLoaderData and render them
23
+ // with <Deferred>
24
+ function DeferredPage() {
25
+ let data = useLoaderData();
26
+ return (
27
+ <>
28
+ <p>Critical Data: {data.critical}</p>
29
+ <Deferred
30
+ value={data.lazy}
31
+ fallback={<p>Loading...</p>}
32
+ errorElement={<RenderDeferredError />}>
33
+ <RenderDeferredData />
34
+ </Deferred>
35
+ </>
36
+ );
37
+ }
38
+
39
+ // Use separate components to render the data once it resolves, and access it
40
+ // via the useDeferredData hook
41
+ function RenderDeferredData() {
42
+ let data = useDeferredData();
43
+ return <p>Lazy: {data}</p>;
44
+ }
45
+
46
+ function RenderDeferredError() {
47
+ let data = useRouteError();
48
+ return <p>Error! {data.message} {data.stack}</p>;
49
+ }
50
+ ```
51
+
52
+ If you want to skip the separate components, you can use the Render Props
53
+ pattern and handle the rendering of the deferred data inline:
54
+
55
+ ```jsx
56
+ function DeferredPage() {
57
+ let data = useLoaderData();
58
+ return (
59
+ <>
60
+ <p>Critical Data: {data.critical}</p>
61
+ <Deferred value={data.lazy} fallback={<p>Loading...</p>}>
62
+ {(data) => <p>{data}</p>}
63
+ </Deferred>
64
+ </>
65
+ );
66
+ }
67
+ ```
68
+
69
+ - feat: add basename support for data routers (#9026)
70
+ - fix: Fix trailing slash behavior on pathless routing when using a basename (#9045)
71
+ - Updated dependencies
72
+ - @remix-run/router@0.2.0-pre.4
73
+
74
+ ## 6.4.0-pre.8
75
+
76
+ ### Patch Changes
77
+
78
+ - fix: Make path resolution trailing slash agnostic (#8861)
79
+ - fix: Additional logic fixed for relative navigation from index/pathless layout routes (#8985)
80
+ - fix: export ActionFunctionArgs/LoaderFunctionArgs up through router packages (#8975)
81
+ - Updated dependencies
82
+ - @remix-run/router@0.2.0-pre.3
83
+
84
+ ## 6.4.0-pre.7
85
+
86
+ ### Minor Changes
87
+
88
+ - Add support for functional updates in `useSearchParams` (similar to the `useState` callback signature) (#8955)
89
+
90
+ ### Patch Changes
91
+
92
+ - Properly handle relative navigation from index/pathless routes (#8954)
93
+ - Fix issues building with webpack + React 17 (#8938)
94
+ - Updated dependencies
95
+ - `@remix-run/router@0.2.0-pre.2`
96
+
3
97
  ## 6.4.0-pre.6
4
98
 
5
99
  ## 6.4.0-pre.5
@@ -12,7 +106,7 @@
12
106
 
13
107
  ### Patch Changes
14
108
 
15
- - 031d5d1f: Fix missing dist files
109
+ - Fix missing `dist` files
16
110
 
17
111
  ## 6.4.0-pre.3
18
112
 
package/dist/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import type { ActionFunction, DataRouteMatch, Fetcher, JsonFunction, LoaderFunction, Location, Navigation, Params, ParamParseKey, Path, PathMatch, PathPattern, RedirectFunction, RouteMatch, RouteObject, ShouldRevalidateFunction, To } from "@remix-run/router";
2
- import { Action as NavigationType, createPath, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, resolvePath } from "@remix-run/router";
3
- import type { DataMemoryRouterProps, MemoryRouterProps, NavigateProps, OutletProps, RouteProps, PathRouteProps, LayoutRouteProps, IndexRouteProps, RouterProps, RoutesProps } from "./lib/components";
4
- import { createRoutesFromChildren, renderMatches, MemoryRouter, DataMemoryRouter, Navigate, Outlet, Route, Router, Routes, useRenderDataRouter, _resetModuleScope } from "./lib/components";
1
+ import type { ActionFunction, ActionFunctionArgs, DataRouteMatch, Fetcher, JsonFunction, LoaderFunction, LoaderFunctionArgs, Location, Navigation, Params, ParamParseKey, Path, PathMatch, PathPattern, RedirectFunction, RouteMatch, RouteObject, ShouldRevalidateFunction, To } from "@remix-run/router";
2
+ import { Action as NavigationType, createPath, deferred, generatePath, isDeferredError, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, resolvePath } from "@remix-run/router";
3
+ import type { DataMemoryRouterProps, DeferredProps, MemoryRouterProps, NavigateProps, OutletProps, RouteProps, PathRouteProps, LayoutRouteProps, IndexRouteProps, RouterProps, RoutesProps } from "./lib/components";
4
+ import { createRoutesFromChildren, renderMatches, DataMemoryRouter, Deferred, MemoryRouter, Navigate, Outlet, Route, Router, Routes, useRenderDataRouter } from "./lib/components";
5
5
  import type { Navigator, NavigateOptions } from "./lib/context";
6
6
  import { DataRouterContext, DataRouterStateContext, LocationContext, NavigationContext, RouteContext } from "./lib/context";
7
- import type { NavigateFunction } from "./lib/hooks";
8
- import { useHref, useInRouterContext, useLocation, useMatch, useNavigationType, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useActionData, useLoaderData, useMatches, useRouteLoaderData, useRouteError, useNavigation, useRevalidator } from "./lib/hooks";
7
+ import type { Deferrable, NavigateFunction } from "./lib/hooks";
8
+ import { useHref, useInRouterContext, useLocation, useMatch, useNavigationType, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useActionData, useDeferredData, useLoaderData, useMatches, useRouteLoaderData, useRouteError, useNavigation, useRevalidator } from "./lib/hooks";
9
9
  declare type Hash = string;
10
10
  declare type Pathname = string;
11
11
  declare type Search = string;
12
- export type { ActionFunction, DataMemoryRouterProps, DataRouteMatch, Fetcher, Hash, IndexRouteProps, JsonFunction, LayoutRouteProps, LoaderFunction, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RouteMatch, RouteObject, RouteProps, RouterProps, RoutesProps, Search, ShouldRevalidateFunction, To, };
13
- export { DataMemoryRouter, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, createPath, createRoutesFromChildren, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, };
12
+ export type { ActionFunction, ActionFunctionArgs, DataMemoryRouterProps, DataRouteMatch, Deferrable, DeferredProps, Fetcher, Hash, IndexRouteProps, JsonFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RouteMatch, RouteObject, RouteProps, RouterProps, RoutesProps, Search, ShouldRevalidateFunction, To, };
13
+ export { DataMemoryRouter, Deferred, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, createPath, createRoutesFromChildren, deferred, isDeferredError, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useDeferredData, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, };
14
14
  /** @internal */
15
- export { NavigationContext as UNSAFE_NavigationContext, LocationContext as UNSAFE_LocationContext, RouteContext as UNSAFE_RouteContext, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, _resetModuleScope as UNSAFE_resetModuleScope, useRenderDataRouter, };
15
+ export { NavigationContext as UNSAFE_NavigationContext, LocationContext as UNSAFE_LocationContext, RouteContext as UNSAFE_RouteContext, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, useRenderDataRouter, };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v6.4.0-pre.6
2
+ * React Router v6.4.0-pre.9
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -8,8 +8,8 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- import { invariant, resolveTo, getToPathname, joinPaths, matchPath, warning, parsePath, matchRoutes, isRouteErrorResponse, createMemoryHistory, Action, normalizePathname, stripBasename, createMemoryRouter } from '@remix-run/router';
12
- export { Action as NavigationType, createPath, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, resolvePath } from '@remix-run/router';
11
+ import { invariant, resolveTo, joinPaths, matchPath, warning, parsePath, matchRoutes, isDeferredError, isRouteErrorResponse, createMemoryHistory, Action, stripBasename, createMemoryRouter } from '@remix-run/router';
12
+ export { Action as NavigationType, createPath, deferred, generatePath, isDeferredError, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, resolvePath } from '@remix-run/router';
13
13
  import * as React from 'react';
14
14
 
15
15
  /**
@@ -191,6 +191,7 @@ const shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore
191
191
  const useSyncExternalStore = "useSyncExternalStore" in React ? // @ts-expect-error
192
192
  (module => module.useSyncExternalStore)(React) : shim;
193
193
 
194
+ // Contexts for data routers
194
195
  const DataRouterContext = /*#__PURE__*/React.createContext(null);
195
196
 
196
197
  if (process.env.NODE_ENV !== "production") {
@@ -203,6 +204,12 @@ if (process.env.NODE_ENV !== "production") {
203
204
  DataRouterStateContext.displayName = "DataRouterState";
204
205
  }
205
206
 
207
+ const DeferredContext = /*#__PURE__*/React.createContext(null);
208
+
209
+ if (process.env.NODE_ENV !== "production") {
210
+ DeferredContext.displayName = "Deferred";
211
+ }
212
+
206
213
  const NavigationContext = /*#__PURE__*/React.createContext(null);
207
214
 
208
215
  if (process.env.NODE_ENV !== "production") {
@@ -250,12 +257,13 @@ function useHref(to) {
250
257
  pathname,
251
258
  search
252
259
  } = useResolvedPath(to);
253
- let joinedPathname = pathname;
260
+ let joinedPathname = pathname; // If we're operating within a basename, prepend it to the pathname prior
261
+ // to creating the href. If this is a root navigation, then just use the raw
262
+ // basename which allows the basename to have full control over the presence
263
+ // of a trailing slash on root links
254
264
 
255
265
  if (basename !== "/") {
256
- let toPathname = getToPathname(to);
257
- let endsWithSlash = toPathname != null && toPathname.endsWith("/");
258
- joinedPathname = pathname === "/" ? basename + (endsWithSlash ? "/" : "") : joinPaths([basename, pathname]);
266
+ joinedPathname = pathname === "/" ? basename : joinPaths([basename, pathname]);
259
267
  }
260
268
 
261
269
  return navigator.createHref({
@@ -317,6 +325,34 @@ function useMatch(pattern) {
317
325
  } = useLocation();
318
326
  return React.useMemo(() => matchPath(pattern, pathname), [pathname, pattern]);
319
327
  }
328
+ /**
329
+ * The interface for the navigate() function returned from useNavigate().
330
+ */
331
+
332
+ /**
333
+ * When processing relative navigation we want to ignore ancestor routes that
334
+ * do not contribute to the path, such that index/pathless layout routes don't
335
+ * interfere.
336
+ *
337
+ * For example, when moving a route element into an index route and/or a
338
+ * pathless layout route, relative link behavior contained within should stay
339
+ * the same. Both of the following examples should link back to the root:
340
+ *
341
+ * <Route path="/">
342
+ * <Route path="accounts" element={<Link to=".."}>
343
+ * </Route>
344
+ *
345
+ * <Route path="/">
346
+ * <Route path="accounts">
347
+ * <Route element={<AccountsLayout />}> // <-- Does not contribute
348
+ * <Route index element={<Link to=".."} /> // <-- Does not contribute
349
+ * </Route
350
+ * </Route>
351
+ * </Route>
352
+ */
353
+ function getPathContributingMatches(matches) {
354
+ return matches.filter((match, index) => index === 0 || !match.route.index && match.pathnameBase !== matches[index - 1].pathnameBase);
355
+ }
320
356
  /**
321
357
  * Returns an imperative method for changing the location. Used by <Link>s, but
322
358
  * may also be used by other elements to change the location.
@@ -324,6 +360,7 @@ function useMatch(pattern) {
324
360
  * @see https://reactrouter.com/docs/en/v6/hooks/use-navigate
325
361
  */
326
362
 
363
+
327
364
  function useNavigate() {
328
365
  !useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
329
366
  // router loaded. We can help them understand how to avoid that.
@@ -337,15 +374,8 @@ function useNavigate() {
337
374
  } = React.useContext(RouteContext);
338
375
  let {
339
376
  pathname: locationPathname
340
- } = useLocation(); // Ignore pathless matches (i.e., share the same pathname as their ancestor)
341
-
342
- let pathContributingMatches = matches.filter((match, index) => index === 0 || match.pathnameBase !== matches[index - 1].pathnameBase);
343
-
344
- if (matches.length > 0 && matches[matches.length - 1].route.index) {
345
- pathContributingMatches.pop();
346
- }
347
-
348
- let routePathnamesJson = JSON.stringify(pathContributingMatches.map(match => match.pathnameBase));
377
+ } = useLocation();
378
+ let routePathnamesJson = JSON.stringify(getPathContributingMatches(matches).map(match => match.pathnameBase));
349
379
  let activeRef = React.useRef(false);
350
380
  React.useEffect(() => {
351
381
  activeRef.current = true;
@@ -363,10 +393,13 @@ function useNavigate() {
363
393
  return;
364
394
  }
365
395
 
366
- let path = resolveTo(to, JSON.parse(routePathnamesJson), locationPathname);
396
+ let path = resolveTo(to, JSON.parse(routePathnamesJson), locationPathname); // If we're operating within a basename, prepend it to the pathname prior
397
+ // to handing off to history. If this is a root navigation, then we
398
+ // navigate to the raw basename which allows the basename to have full
399
+ // control over the presence of a trailing slash on root links
367
400
 
368
401
  if (basename !== "/") {
369
- path.pathname = joinPaths([basename, path.pathname]);
402
+ path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
370
403
  }
371
404
 
372
405
  (!!options.replace ? navigator.replace : navigator.push)(path, options.state, options);
@@ -428,7 +461,7 @@ function useResolvedPath(to) {
428
461
  let {
429
462
  pathname: locationPathname
430
463
  } = useLocation();
431
- let routePathnamesJson = JSON.stringify(matches.map(match => match.pathnameBase));
464
+ let routePathnamesJson = JSON.stringify(getPathContributingMatches(matches).map(match => match.pathnameBase));
432
465
  return React.useMemo(() => resolveTo(to, JSON.parse(routePathnamesJson), locationPathname), [to, routePathnamesJson, locationPathname]);
433
466
  }
434
467
  /**
@@ -528,9 +561,9 @@ function DefaultErrorElement() {
528
561
  }
529
562
  }, message), error != null && error.stack ? /*#__PURE__*/React.createElement("pre", {
530
563
  style: preStyles
531
- }, error == null ? void 0 : error.stack) : 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\u00A0", /*#__PURE__*/React.createElement("code", {
564
+ }, error == null ? void 0 : error.stack) : 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\xA0", /*#__PURE__*/React.createElement("code", {
532
565
  style: codeStyles
533
- }, "errorElement"), " props on\u00A0", /*#__PURE__*/React.createElement("code", {
566
+ }, "errorElement"), " props on\xA0", /*#__PURE__*/React.createElement("code", {
534
567
  style: codeStyles
535
568
  }, "<Route>")));
536
569
  }
@@ -707,24 +740,20 @@ function useMatches() {
707
740
  */
708
741
 
709
742
  function useLoaderData() {
710
- var _state$loaderData;
711
-
712
743
  let state = useDataRouterState(DataRouterHook.UseLoaderData);
713
744
  let route = React.useContext(RouteContext);
714
745
  !route ? process.env.NODE_ENV !== "production" ? invariant(false, "useLoaderData must be used inside a RouteContext") : invariant(false) : void 0;
715
746
  let thisRoute = route.matches[route.matches.length - 1];
716
747
  !thisRoute.route.id ? process.env.NODE_ENV !== "production" ? invariant(false, "useLoaderData can only be used on routes that contain a unique \"id\"") : invariant(false) : void 0;
717
- return (_state$loaderData = state.loaderData) == null ? void 0 : _state$loaderData[thisRoute.route.id];
748
+ return state.loaderData[thisRoute.route.id];
718
749
  }
719
750
  /**
720
751
  * Returns the loaderData for the given routeId
721
752
  */
722
753
 
723
754
  function useRouteLoaderData(routeId) {
724
- var _state$loaderData2;
725
-
726
755
  let state = useDataRouterState(DataRouterHook.UseRouteLoaderData);
727
- return (_state$loaderData2 = state.loaderData) == null ? void 0 : _state$loaderData2[routeId];
756
+ return state.loaderData[routeId];
728
757
  }
729
758
  /**
730
759
  * Returns the action data for the nearest ancestor Route action
@@ -748,9 +777,15 @@ function useRouteError() {
748
777
  let error = React.useContext(RouteErrorContext);
749
778
  let state = useDataRouterState(DataRouterHook.UseRouteError);
750
779
  let route = React.useContext(RouteContext);
751
- let thisRoute = route.matches[route.matches.length - 1]; // If this was a render error, we put it in a RouteError context inside
780
+ let thisRoute = route.matches[route.matches.length - 1];
781
+ let deferredValue = React.useContext(DeferredContext); // Return deferred errors if we're inside a Deferred errorElement
782
+
783
+ if (deferredValue && isDeferredError(deferredValue)) {
784
+ return deferredValue;
785
+ } // If this was a render error, we put it in a RouteError context inside
752
786
  // of RenderErrorBoundary
753
787
 
788
+
754
789
  if (error) {
755
790
  return error;
756
791
  }
@@ -760,6 +795,14 @@ function useRouteError() {
760
795
 
761
796
  return (_state$errors = state.errors) == null ? void 0 : _state$errors[thisRoute.route.id];
762
797
  }
798
+
799
+ /**
800
+ * Returns the happy-path data from the nearest ancestor <Deferred /> value
801
+ */
802
+ function useDeferredData() {
803
+ let value = React.useContext(DeferredContext);
804
+ return value;
805
+ }
763
806
  const alreadyWarned = {};
764
807
 
765
808
  function warningOnce(key, cond, message) {
@@ -774,21 +817,13 @@ function warningOnce(key, cond, message) {
774
817
  // to be unmounted/remounted at runtime.
775
818
 
776
819
  let routerSingleton;
777
- /**
778
- * Unit-testing-only function to reset the router between tests
779
- * @private
780
- */
781
-
782
- function _resetModuleScope() {
783
- // @ts-expect-error
784
- routerSingleton = null;
785
- }
786
820
  /**
787
821
  * @private
788
822
  */
789
823
 
790
824
  function useRenderDataRouter(_ref) {
791
825
  let {
826
+ basename,
792
827
  children,
793
828
  fallbackElement,
794
829
  routes,
@@ -827,6 +862,7 @@ function useRenderDataRouter(_ref) {
827
862
  }, /*#__PURE__*/React.createElement(DataRouterStateContext.Provider, {
828
863
  value: state
829
864
  }, /*#__PURE__*/React.createElement(Router, {
865
+ basename: basename,
830
866
  location: state.location,
831
867
  navigationType: state.historyAction,
832
868
  navigator: navigator
@@ -837,6 +873,7 @@ function useRenderDataRouter(_ref) {
837
873
  }
838
874
  function DataMemoryRouter(_ref2) {
839
875
  let {
876
+ basename,
840
877
  children,
841
878
  initialEntries,
842
879
  initialIndex,
@@ -845,10 +882,12 @@ function DataMemoryRouter(_ref2) {
845
882
  routes
846
883
  } = _ref2;
847
884
  return useRenderDataRouter({
885
+ basename,
848
886
  children,
849
887
  fallbackElement,
850
888
  routes,
851
889
  createRouter: routes => createMemoryRouter({
890
+ basename,
852
891
  initialEntries,
853
892
  initialIndex,
854
893
  routes,
@@ -856,12 +895,12 @@ function DataMemoryRouter(_ref2) {
856
895
  })
857
896
  });
858
897
  }
898
+
859
899
  /**
860
900
  * A <Router> that stores all entries in memory.
861
901
  *
862
902
  * @see https://reactrouter.com/docs/en/v6/routers/memory-router
863
903
  */
864
-
865
904
  function MemoryRouter(_ref3) {
866
905
  let {
867
906
  basename,
@@ -893,6 +932,7 @@ function MemoryRouter(_ref3) {
893
932
  navigator: history
894
933
  });
895
934
  }
935
+
896
936
  /**
897
937
  * Changes the current location.
898
938
  *
@@ -902,7 +942,6 @@ function MemoryRouter(_ref3) {
902
942
  *
903
943
  * @see https://reactrouter.com/docs/en/v6/components/navigate
904
944
  */
905
-
906
945
  function Navigate(_ref4) {
907
946
  let {
908
947
  to,
@@ -922,24 +961,25 @@ function Navigate(_ref4) {
922
961
  });
923
962
  return null;
924
963
  }
964
+
925
965
  /**
926
966
  * Renders the child route's element, if there is one.
927
967
  *
928
968
  * @see https://reactrouter.com/docs/en/v6/components/outlet
929
969
  */
930
-
931
970
  function Outlet(props) {
932
971
  return useOutlet(props.context);
933
972
  }
973
+
934
974
  /**
935
975
  * Declares an element that should be rendered at a certain URL path.
936
976
  *
937
977
  * @see https://reactrouter.com/docs/en/v6/components/route
938
978
  */
939
-
940
979
  function Route(_props) {
941
980
  process.env.NODE_ENV !== "production" ? 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>.") : invariant(false) ;
942
981
  }
982
+
943
983
  /**
944
984
  * Provides location context for the rest of the app.
945
985
  *
@@ -949,7 +989,6 @@ function Route(_props) {
949
989
  *
950
990
  * @see https://reactrouter.com/docs/en/v6/routers/router
951
991
  */
952
-
953
992
  function Router(_ref5) {
954
993
  let {
955
994
  basename: basenameProp = "/",
@@ -959,8 +998,10 @@ function Router(_ref5) {
959
998
  navigator,
960
999
  static: staticProp = false
961
1000
  } = _ref5;
962
- !!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(false, "You cannot render a <Router> inside another <Router>." + " You should never have more than one in your app.") : invariant(false) : void 0;
963
- let basename = normalizePathname(basenameProp);
1001
+ !!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(false, "You cannot render a <Router> inside another <Router>." + " You should never have more than one in your app.") : invariant(false) : void 0; // Preserve trailing slashes on basename, so we can let the user control
1002
+ // the enforcement of trailing slashes throughout the app
1003
+
1004
+ let basename = basenameProp.replace(/^\/*/, "/");
964
1005
  let navigationContext = React.useMemo(() => ({
965
1006
  basename,
966
1007
  navigator,
@@ -1009,13 +1050,13 @@ function Router(_ref5) {
1009
1050
  }
1010
1051
  }));
1011
1052
  }
1053
+
1012
1054
  /**
1013
1055
  * A container for a nested tree of <Route> elements that renders the branch
1014
1056
  * that best matches the current location.
1015
1057
  *
1016
1058
  * @see https://reactrouter.com/docs/en/v6/components/routes
1017
1059
  */
1018
-
1019
1060
  function Routes(_ref6) {
1020
1061
  let {
1021
1062
  children,
@@ -1023,13 +1064,13 @@ function Routes(_ref6) {
1023
1064
  } = _ref6;
1024
1065
  return useRoutes(createRoutesFromChildren(children), location);
1025
1066
  }
1067
+
1026
1068
  /**
1027
1069
  * @private
1028
1070
  * Used as an extension to <Routes> and accepts a manual `routes` array to be
1029
1071
  * instead of using JSX children. Extracted to it's own component to avoid
1030
1072
  * conditional usage of `useRoutes` if we have to render a `fallbackElement`
1031
1073
  */
1032
-
1033
1074
  function DataRoutes(_ref7) {
1034
1075
  let {
1035
1076
  children,
@@ -1037,6 +1078,68 @@ function DataRoutes(_ref7) {
1037
1078
  routes
1038
1079
  } = _ref7;
1039
1080
  return useRoutes(routes || createRoutesFromChildren(children), location);
1081
+ }
1082
+
1083
+ /**
1084
+ * Component to use for rendering lazily loaded data from returning deferred()
1085
+ * in a loader function
1086
+ */
1087
+ function Deferred(_ref8) {
1088
+ let {
1089
+ children,
1090
+ value,
1091
+ fallback,
1092
+ errorElement
1093
+ } = _ref8;
1094
+ return /*#__PURE__*/React.createElement(DeferredContext.Provider, {
1095
+ value: value
1096
+ }, /*#__PURE__*/React.createElement(React.Suspense, {
1097
+ fallback: fallback
1098
+ }, /*#__PURE__*/React.createElement(DeferredWrapper, {
1099
+ errorElement: errorElement
1100
+ }, typeof children === "function" ? /*#__PURE__*/React.createElement(ResolveDeferred, {
1101
+ children: children
1102
+ }) : children)));
1103
+ }
1104
+
1105
+ /**
1106
+ * @private
1107
+ * Internal wrapper to handle re-throwing the promise to trigger the Suspense
1108
+ * fallback, or rendering the children/errorElement once the promise resolves
1109
+ * or rejects
1110
+ */
1111
+ function DeferredWrapper(_ref9) {
1112
+ let {
1113
+ children,
1114
+ errorElement
1115
+ } = _ref9;
1116
+ let value = React.useContext(DeferredContext);
1117
+
1118
+ if (value instanceof Promise) {
1119
+ // throw to the suspense boundary
1120
+ throw value;
1121
+ }
1122
+
1123
+ if (isDeferredError(value)) {
1124
+ if (errorElement) {
1125
+ return /*#__PURE__*/React.createElement(React.Fragment, null, errorElement);
1126
+ } else {
1127
+ // Throw to the nearest route-level error boundary
1128
+ throw value;
1129
+ }
1130
+ }
1131
+
1132
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children);
1133
+ }
1134
+
1135
+ /**
1136
+ * @private
1137
+ */
1138
+ function ResolveDeferred(_ref10) {
1139
+ let {
1140
+ children
1141
+ } = _ref10;
1142
+ return children(useDeferredData());
1040
1143
  } ///////////////////////////////////////////////////////////////////////////////
1041
1144
  // UTILS
1042
1145
  ///////////////////////////////////////////////////////////////////////////////
@@ -1049,7 +1152,6 @@ function DataRoutes(_ref7) {
1049
1152
  * @see https://reactrouter.com/docs/en/v6/utils/create-routes-from-children
1050
1153
  */
1051
1154
 
1052
-
1053
1155
  function createRoutesFromChildren(children, parentPath) {
1054
1156
  if (parentPath === void 0) {
1055
1157
  parentPath = [];
@@ -1100,5 +1202,5 @@ function renderMatches(matches) {
1100
1202
  return _renderMatches(matches);
1101
1203
  }
1102
1204
 
1103
- export { DataMemoryRouter, MemoryRouter, Navigate, Outlet, Route, Router, Routes, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RouteContext as UNSAFE_RouteContext, _resetModuleScope as UNSAFE_resetModuleScope, createRoutesFromChildren, renderMatches, useActionData, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useRenderDataRouter, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes };
1205
+ export { DataMemoryRouter, Deferred, MemoryRouter, Navigate, Outlet, Route, Router, Routes, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RouteContext as UNSAFE_RouteContext, createRoutesFromChildren, renderMatches, useActionData, useDeferredData, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useRenderDataRouter, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes };
1104
1206
  //# sourceMappingURL=index.js.map