react-router 0.0.0-experimental-e7e9ce6e → 0.0.0-experimental-91f2bf54
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 +2 -20
- package/dist/index.d.ts +5 -4
- package/dist/index.js +113 -91
- package/dist/index.js.map +1 -1
- package/dist/lib/components.d.ts +7 -7
- package/dist/lib/context.d.ts +7 -1
- package/dist/lib/hooks.d.ts +1 -1
- package/dist/main.js +1 -1
- package/dist/react-router.development.js +96 -75
- package/dist/react-router.development.js.map +1 -1
- package/dist/react-router.production.min.js +2 -2
- package/dist/react-router.production.min.js.map +1 -1
- package/dist/umd/react-router.development.js +112 -90
- package/dist/umd/react-router.development.js.map +1 -1
- package/dist/umd/react-router.production.min.js +2 -2
- package/dist/umd/react-router.production.min.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
# `react-router`
|
|
2
2
|
|
|
3
|
-
## 6.8.2
|
|
4
|
-
|
|
5
|
-
## 6.8.2-pre.2
|
|
6
|
-
|
|
7
|
-
### Patch Changes
|
|
8
|
-
|
|
9
|
-
- Updated dependencies:
|
|
10
|
-
- `@remix-run/router@1.3.3-pre.1`
|
|
11
|
-
|
|
12
|
-
## 6.8.2-pre.1
|
|
13
|
-
|
|
14
|
-
## 6.8.2-pre.0
|
|
3
|
+
## 6.8.2
|
|
15
4
|
|
|
16
5
|
### Patch Changes
|
|
17
6
|
|
|
18
7
|
- Updated dependencies:
|
|
19
|
-
- `@remix-run/router@1.3.3
|
|
8
|
+
- `@remix-run/router@1.3.3`
|
|
20
9
|
|
|
21
10
|
## 6.8.1
|
|
22
11
|
|
|
@@ -33,13 +22,6 @@
|
|
|
33
22
|
- Updated dependencies:
|
|
34
23
|
- `@remix-run/router@1.3.1`
|
|
35
24
|
|
|
36
|
-
## 6.7.1-pre.0
|
|
37
|
-
|
|
38
|
-
### Patch Changes
|
|
39
|
-
|
|
40
|
-
- Updated dependencies:
|
|
41
|
-
- `@remix-run/router@1.3.1-pre.0`
|
|
42
|
-
|
|
43
25
|
## 6.7.0
|
|
44
26
|
|
|
45
27
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ActionFunction, ActionFunctionArgs, Blocker, BlockerFunction, Fetcher, HydrationState, JsonFunction, LoaderFunction, LoaderFunctionArgs, Location, Navigation, Params, ParamParseKey, Path, PathMatch, PathPattern, RedirectFunction, Router as RemixRouter, ShouldRevalidateFunction, To, InitialEntry } from "@remix-run/router";
|
|
1
|
+
import type { ActionFunction, ActionFunctionArgs, Blocker, BlockerFunction, Fetcher, HydrationState, JsonFunction, LoaderFunction, LoaderFunctionArgs, Location, Navigation, Params, ParamParseKey, Path, PathMatch, PathPattern, RedirectFunction, Router as RemixRouter, ShouldRevalidateFunction, To, InitialEntry, LazyRouteFunction } from "@remix-run/router";
|
|
2
2
|
import { AbortedDeferredError, Action as NavigationType, createPath, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, resolvePath } from "@remix-run/router";
|
|
3
3
|
import type { AwaitProps, MemoryRouterProps, NavigateProps, OutletProps, RouteProps, PathRouteProps, LayoutRouteProps, IndexRouteProps, RouterProps, RoutesProps, RouterProviderProps } from "./lib/components";
|
|
4
|
-
import {
|
|
4
|
+
import { createRoutesFromChildren, renderMatches, Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes } from "./lib/components";
|
|
5
5
|
import type { DataRouteMatch, DataRouteObject, IndexRouteObject, Navigator, NavigateOptions, NonIndexRouteObject, RouteMatch, RouteObject, RelativeRoutingType } from "./lib/context";
|
|
6
6
|
import { DataRouterContext, DataRouterStateContext, LocationContext, NavigationContext, RouteContext } from "./lib/context";
|
|
7
7
|
import type { NavigateFunction } from "./lib/hooks";
|
|
@@ -9,8 +9,9 @@ import { useBlocker, useHref, useInRouterContext, useLocation, useMatch, useNavi
|
|
|
9
9
|
declare type Hash = string;
|
|
10
10
|
declare type Pathname = string;
|
|
11
11
|
declare type Search = string;
|
|
12
|
-
export type { ActionFunction, ActionFunctionArgs, AwaitProps, Blocker as unstable_Blocker, BlockerFunction as unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, To, };
|
|
12
|
+
export type { ActionFunction, ActionFunctionArgs, AwaitProps, Blocker as unstable_Blocker, BlockerFunction as unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LazyRouteFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, To, };
|
|
13
13
|
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, createPath, createRoutesFromChildren, createRoutesFromChildren as createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, useBlocker as unstable_useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, };
|
|
14
|
+
declare function detectErrorBoundary(route: RouteObject): boolean;
|
|
14
15
|
export declare function createMemoryRouter(routes: RouteObject[], opts?: {
|
|
15
16
|
basename?: string;
|
|
16
17
|
hydrationData?: HydrationState;
|
|
@@ -18,4 +19,4 @@ export declare function createMemoryRouter(routes: RouteObject[], opts?: {
|
|
|
18
19
|
initialIndex?: number;
|
|
19
20
|
}): RemixRouter;
|
|
20
21
|
/** @internal */
|
|
21
|
-
export { NavigationContext as UNSAFE_NavigationContext, LocationContext as UNSAFE_LocationContext, RouteContext as UNSAFE_RouteContext, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext,
|
|
22
|
+
export { NavigationContext as UNSAFE_NavigationContext, LocationContext as UNSAFE_LocationContext, RouteContext as UNSAFE_RouteContext, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, detectErrorBoundary as UNSAFE_detectErrorBoundary, };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v0.0.0-experimental-
|
|
2
|
+
* React Router v0.0.0-experimental-91f2bf54
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,27 +8,10 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import { UNSAFE_invariant, joinPaths, matchPath, UNSAFE_getPathContributingMatches,
|
|
11
|
+
import { UNSAFE_invariant, joinPaths, matchPath, UNSAFE_getPathContributingMatches, UNSAFE_warning, resolveTo, parsePath, matchRoutes, Action, isRouteErrorResponse, createMemoryHistory, stripBasename, AbortedDeferredError, createRouter } from '@remix-run/router';
|
|
12
12
|
export { AbortedDeferredError, Action as NavigationType, createPath, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, resolvePath } from '@remix-run/router';
|
|
13
13
|
import * as React from 'react';
|
|
14
14
|
|
|
15
|
-
function _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
|
-
|
|
32
15
|
/**
|
|
33
16
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
34
17
|
*
|
|
@@ -252,6 +235,23 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
252
235
|
RouteErrorContext.displayName = "RouteError";
|
|
253
236
|
}
|
|
254
237
|
|
|
238
|
+
function _extends() {
|
|
239
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
240
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
241
|
+
var source = arguments[i];
|
|
242
|
+
|
|
243
|
+
for (var key in source) {
|
|
244
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
245
|
+
target[key] = source[key];
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return target;
|
|
251
|
+
};
|
|
252
|
+
return _extends.apply(this, arguments);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
255
|
/**
|
|
256
256
|
* Returns the full href for the given "to" value. This is useful for building
|
|
257
257
|
* custom links that are also accessible and preserve right-click behavior.
|
|
@@ -379,7 +379,7 @@ function useNavigate() {
|
|
|
379
379
|
options = {};
|
|
380
380
|
}
|
|
381
381
|
|
|
382
|
-
process.env.NODE_ENV !== "production" ?
|
|
382
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(activeRef.current, "You should call navigate() in a React.useEffect(), not when " + "your component is first rendered.") : void 0;
|
|
383
383
|
if (!activeRef.current) return;
|
|
384
384
|
|
|
385
385
|
if (typeof to === "number") {
|
|
@@ -532,8 +532,8 @@ function useRoutes(routes, locationArg) {
|
|
|
532
532
|
});
|
|
533
533
|
|
|
534
534
|
if (process.env.NODE_ENV !== "production") {
|
|
535
|
-
process.env.NODE_ENV !== "production" ?
|
|
536
|
-
process.env.NODE_ENV !== "production" ?
|
|
535
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(parentRoute || matches != null, "No routes matched location \"" + location.pathname + location.search + location.hash + "\" ") : void 0;
|
|
536
|
+
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;
|
|
537
537
|
}
|
|
538
538
|
|
|
539
539
|
let renderedMatches = _renderMatches(matches && matches.map(match => Object.assign({}, match, {
|
|
@@ -565,7 +565,7 @@ function useRoutes(routes, locationArg) {
|
|
|
565
565
|
return renderedMatches;
|
|
566
566
|
}
|
|
567
567
|
|
|
568
|
-
function
|
|
568
|
+
function DefaultErrorComponent() {
|
|
569
569
|
let error = useRouteError();
|
|
570
570
|
let message = isRouteErrorResponse(error) ? error.status + " " + error.statusText : error instanceof Error ? error.message : JSON.stringify(error);
|
|
571
571
|
let stack = error instanceof Error ? error.stack : null;
|
|
@@ -583,7 +583,7 @@ function DefaultErrorElement() {
|
|
|
583
583
|
if (process.env.NODE_ENV !== "production") {
|
|
584
584
|
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\xA0", /*#__PURE__*/React.createElement("code", {
|
|
585
585
|
style: codeStyles
|
|
586
|
-
}, "
|
|
586
|
+
}, "ErrorBoundary"), " prop on\xA0", /*#__PURE__*/React.createElement("code", {
|
|
587
587
|
style: codeStyles
|
|
588
588
|
}, "<Route>")));
|
|
589
589
|
}
|
|
@@ -662,7 +662,7 @@ function RenderedRoute(_ref) {
|
|
|
662
662
|
let dataRouterContext = React.useContext(DataRouterContext); // Track how deep we got in our render pass to emulate SSR componentDidCatch
|
|
663
663
|
// in a DataStaticRouter
|
|
664
664
|
|
|
665
|
-
if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && match.route.errorElement) {
|
|
665
|
+
if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) {
|
|
666
666
|
dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
|
|
667
667
|
}
|
|
668
668
|
|
|
@@ -699,21 +699,45 @@ function _renderMatches(matches, parentMatches, dataRouterState) {
|
|
|
699
699
|
return renderedMatches.reduceRight((outlet, match, index) => {
|
|
700
700
|
let error = match.route.id ? errors == null ? void 0 : errors[match.route.id] : null; // Only data routers handle errors
|
|
701
701
|
|
|
702
|
-
let errorElement =
|
|
702
|
+
let errorElement = null;
|
|
703
|
+
|
|
704
|
+
if (dataRouterState) {
|
|
705
|
+
if (match.route.ErrorBoundary) {
|
|
706
|
+
errorElement = /*#__PURE__*/React.createElement(match.route.ErrorBoundary, null);
|
|
707
|
+
} else if (match.route.errorElement) {
|
|
708
|
+
errorElement = match.route.errorElement;
|
|
709
|
+
} else {
|
|
710
|
+
errorElement = /*#__PURE__*/React.createElement(DefaultErrorComponent, null);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
703
714
|
let matches = parentMatches.concat(renderedMatches.slice(0, index + 1));
|
|
704
715
|
|
|
705
|
-
let getChildren = () =>
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
716
|
+
let getChildren = () => {
|
|
717
|
+
let children = outlet;
|
|
718
|
+
|
|
719
|
+
if (error) {
|
|
720
|
+
children = errorElement;
|
|
721
|
+
} else if (match.route.Component) {
|
|
722
|
+
children = /*#__PURE__*/React.createElement(match.route.Component, null);
|
|
723
|
+
} else if (match.route.element) {
|
|
724
|
+
children = match.route.element;
|
|
710
725
|
}
|
|
711
|
-
}, error ? errorElement : match.route.element !== undefined ? match.route.element : outlet); // Only wrap in an error boundary within data router usages when we have an
|
|
712
|
-
// errorElement on this route. Otherwise let it bubble up to an ancestor
|
|
713
|
-
// errorElement
|
|
714
726
|
|
|
727
|
+
return /*#__PURE__*/React.createElement(RenderedRoute, {
|
|
728
|
+
match: match,
|
|
729
|
+
routeContext: {
|
|
730
|
+
outlet,
|
|
731
|
+
matches
|
|
732
|
+
},
|
|
733
|
+
children: children
|
|
734
|
+
});
|
|
735
|
+
}; // Only wrap in an error boundary within data router usages when we have an
|
|
736
|
+
// ErrorBoundary/errorElement on this route. Otherwise let it bubble up to
|
|
737
|
+
// an ancestor ErrorBoundary/errorElement
|
|
715
738
|
|
|
716
|
-
|
|
739
|
+
|
|
740
|
+
return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? /*#__PURE__*/React.createElement(RenderErrorBoundary, {
|
|
717
741
|
location: dataRouterState.location,
|
|
718
742
|
component: errorElement,
|
|
719
743
|
error: error,
|
|
@@ -735,6 +759,7 @@ var DataRouterHook;
|
|
|
735
759
|
var DataRouterStateHook;
|
|
736
760
|
|
|
737
761
|
(function (DataRouterStateHook) {
|
|
762
|
+
DataRouterStateHook["UseBlocker"] = "useBlocker";
|
|
738
763
|
DataRouterStateHook["UseLoaderData"] = "useLoaderData";
|
|
739
764
|
DataRouterStateHook["UseActionData"] = "useActionData";
|
|
740
765
|
DataRouterStateHook["UseRouteError"] = "useRouteError";
|
|
@@ -858,7 +883,7 @@ function useActionData() {
|
|
|
858
883
|
/**
|
|
859
884
|
* Returns the nearest ancestor Route error, which could be a loader/action
|
|
860
885
|
* error or a render error. This is intended to be called from your
|
|
861
|
-
* errorElement to display a proper error message.
|
|
886
|
+
* ErrorBoundary/errorElement to display a proper error message.
|
|
862
887
|
*/
|
|
863
888
|
|
|
864
889
|
function useRouteError() {
|
|
@@ -904,21 +929,24 @@ function useBlocker(shouldBlock) {
|
|
|
904
929
|
let {
|
|
905
930
|
router
|
|
906
931
|
} = useDataRouterContext(DataRouterHook.UseBlocker);
|
|
932
|
+
let state = useDataRouterState(DataRouterStateHook.UseBlocker);
|
|
907
933
|
let [blockerKey] = React.useState(() => String(++blockerId));
|
|
908
934
|
let blockerFunction = React.useCallback(args => {
|
|
909
935
|
return typeof shouldBlock === "function" ? !!shouldBlock(args) : !!shouldBlock;
|
|
910
936
|
}, [shouldBlock]);
|
|
911
937
|
let blocker = router.getBlocker(blockerKey, blockerFunction); // Cleanup on unmount
|
|
912
938
|
|
|
913
|
-
React.useEffect(() => () => router.deleteBlocker(blockerKey), [router, blockerKey]);
|
|
914
|
-
|
|
939
|
+
React.useEffect(() => () => router.deleteBlocker(blockerKey), [router, blockerKey]); // Prefer the blocker from state since DataRouterContext is memoized so this
|
|
940
|
+
// ensures we update on blocker state updates
|
|
941
|
+
|
|
942
|
+
return state.blockers.get(blockerKey) || blocker;
|
|
915
943
|
}
|
|
916
944
|
const alreadyWarned = {};
|
|
917
945
|
|
|
918
946
|
function warningOnce(key, cond, message) {
|
|
919
947
|
if (!cond && !alreadyWarned[key]) {
|
|
920
948
|
alreadyWarned[key] = true;
|
|
921
|
-
process.env.NODE_ENV !== "production" ?
|
|
949
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, message) : void 0;
|
|
922
950
|
}
|
|
923
951
|
}
|
|
924
952
|
|
|
@@ -930,11 +958,12 @@ function RouterProvider(_ref) {
|
|
|
930
958
|
fallbackElement,
|
|
931
959
|
router
|
|
932
960
|
} = _ref;
|
|
933
|
-
// Sync router state to our component state to force re-renders
|
|
934
|
-
|
|
961
|
+
let getState = React.useCallback(() => router.state, [router]); // Sync router state to our component state to force re-renders
|
|
962
|
+
|
|
963
|
+
let state = useSyncExternalStore(router.subscribe, getState, // We have to provide this so React@18 doesn't complain during hydration,
|
|
935
964
|
// but we pass our serialized hydration data into the router so state here
|
|
936
965
|
// is already synced with what the server saw
|
|
937
|
-
|
|
966
|
+
getState);
|
|
938
967
|
let navigator = React.useMemo(() => {
|
|
939
968
|
return {
|
|
940
969
|
createHref: router.createHref,
|
|
@@ -951,7 +980,13 @@ function RouterProvider(_ref) {
|
|
|
951
980
|
})
|
|
952
981
|
};
|
|
953
982
|
}, [router]);
|
|
954
|
-
let basename = router.basename || "/";
|
|
983
|
+
let basename = router.basename || "/";
|
|
984
|
+
let dataRouterContext = React.useMemo(() => ({
|
|
985
|
+
router,
|
|
986
|
+
navigator,
|
|
987
|
+
static: false,
|
|
988
|
+
basename
|
|
989
|
+
}), [router, navigator, basename]); // The fragment and {null} here are important! We need them to keep React 18's
|
|
955
990
|
// useId happy when we are server-rendering since we may have a <script> here
|
|
956
991
|
// containing the hydrated server-side staticContext (from StaticRouterProvider).
|
|
957
992
|
// useId relies on the component tree structure to generate deterministic id's
|
|
@@ -959,13 +994,7 @@ function RouterProvider(_ref) {
|
|
|
959
994
|
// we don't need the <script> tag
|
|
960
995
|
|
|
961
996
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DataRouterContext.Provider, {
|
|
962
|
-
value:
|
|
963
|
-
router,
|
|
964
|
-
navigator,
|
|
965
|
-
static: false,
|
|
966
|
-
// Do we need this?
|
|
967
|
-
basename
|
|
968
|
-
}
|
|
997
|
+
value: dataRouterContext
|
|
969
998
|
}, /*#__PURE__*/React.createElement(DataRouterStateContext.Provider, {
|
|
970
999
|
value: state
|
|
971
1000
|
}, /*#__PURE__*/React.createElement(Router, {
|
|
@@ -1032,7 +1061,7 @@ function Navigate(_ref3) {
|
|
|
1032
1061
|
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of
|
|
1033
1062
|
// the router loaded. We can help them understand how to avoid that.
|
|
1034
1063
|
"<Navigate> may be used only in the context of a <Router> component.") : UNSAFE_invariant(false) : void 0;
|
|
1035
|
-
process.env.NODE_ENV !== "production" ?
|
|
1064
|
+
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;
|
|
1036
1065
|
let dataRouterState = React.useContext(DataRouterStateContext);
|
|
1037
1066
|
let navigate = useNavigate();
|
|
1038
1067
|
React.useEffect(() => {
|
|
@@ -1088,15 +1117,9 @@ function Router(_ref4) {
|
|
|
1088
1117
|
navigator,
|
|
1089
1118
|
static: staticProp = false
|
|
1090
1119
|
} = _ref4;
|
|
1091
|
-
|
|
1092
|
-
// <RouterProvider>
|
|
1093
|
-
// invariant(
|
|
1094
|
-
// !useInRouterContext(),
|
|
1095
|
-
// `You cannot render a <Router> inside another <Router>.` +
|
|
1096
|
-
// ` You should never have more than one in your app.`
|
|
1097
|
-
// );
|
|
1098
|
-
// Preserve trailing slashes on basename, so we can let the user control
|
|
1120
|
+
!!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
|
|
1099
1121
|
// the enforcement of trailing slashes throughout the app
|
|
1122
|
+
|
|
1100
1123
|
let basename = basenameProp.replace(/^\/*/, "/");
|
|
1101
1124
|
let navigationContext = React.useMemo(() => ({
|
|
1102
1125
|
basename,
|
|
@@ -1115,7 +1138,7 @@ function Router(_ref4) {
|
|
|
1115
1138
|
state = null,
|
|
1116
1139
|
key = "default"
|
|
1117
1140
|
} = locationProp;
|
|
1118
|
-
let
|
|
1141
|
+
let locationContext = React.useMemo(() => {
|
|
1119
1142
|
let trailingPathname = stripBasename(pathname, basename);
|
|
1120
1143
|
|
|
1121
1144
|
if (trailingPathname == null) {
|
|
@@ -1123,16 +1146,19 @@ function Router(_ref4) {
|
|
|
1123
1146
|
}
|
|
1124
1147
|
|
|
1125
1148
|
return {
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1149
|
+
location: {
|
|
1150
|
+
pathname: trailingPathname,
|
|
1151
|
+
search,
|
|
1152
|
+
hash,
|
|
1153
|
+
state,
|
|
1154
|
+
key
|
|
1155
|
+
},
|
|
1156
|
+
navigationType
|
|
1131
1157
|
};
|
|
1132
|
-
}, [basename, pathname, search, hash, state, key]);
|
|
1133
|
-
process.env.NODE_ENV !== "production" ?
|
|
1158
|
+
}, [basename, pathname, search, hash, state, key, navigationType]);
|
|
1159
|
+
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;
|
|
1134
1160
|
|
|
1135
|
-
if (
|
|
1161
|
+
if (locationContext == null) {
|
|
1136
1162
|
return null;
|
|
1137
1163
|
}
|
|
1138
1164
|
|
|
@@ -1140,10 +1166,7 @@ function Router(_ref4) {
|
|
|
1140
1166
|
value: navigationContext
|
|
1141
1167
|
}, /*#__PURE__*/React.createElement(LocationContext.Provider, {
|
|
1142
1168
|
children: children,
|
|
1143
|
-
value:
|
|
1144
|
-
location,
|
|
1145
|
-
navigationType
|
|
1146
|
-
}
|
|
1169
|
+
value: locationContext
|
|
1147
1170
|
}));
|
|
1148
1171
|
}
|
|
1149
1172
|
|
|
@@ -1340,14 +1363,17 @@ function createRoutesFromChildren(children, parentPath) {
|
|
|
1340
1363
|
id: element.props.id || treePath.join("-"),
|
|
1341
1364
|
caseSensitive: element.props.caseSensitive,
|
|
1342
1365
|
element: element.props.element,
|
|
1366
|
+
Component: element.props.Component,
|
|
1343
1367
|
index: element.props.index,
|
|
1344
1368
|
path: element.props.path,
|
|
1345
1369
|
loader: element.props.loader,
|
|
1346
1370
|
action: element.props.action,
|
|
1347
1371
|
errorElement: element.props.errorElement,
|
|
1348
|
-
|
|
1372
|
+
ErrorBoundary: element.props.ErrorBoundary,
|
|
1373
|
+
hasErrorBoundary: element.props.ErrorBoundary != null || element.props.errorElement != null,
|
|
1349
1374
|
shouldRevalidate: element.props.shouldRevalidate,
|
|
1350
|
-
handle: element.props.handle
|
|
1375
|
+
handle: element.props.handle,
|
|
1376
|
+
lazy: element.props.lazy
|
|
1351
1377
|
};
|
|
1352
1378
|
|
|
1353
1379
|
if (element.props.children) {
|
|
@@ -1365,26 +1391,21 @@ function createRoutesFromChildren(children, parentPath) {
|
|
|
1365
1391
|
function renderMatches(matches) {
|
|
1366
1392
|
return _renderMatches(matches);
|
|
1367
1393
|
}
|
|
1368
|
-
/**
|
|
1369
|
-
* @private
|
|
1370
|
-
* Walk the route tree and add hasErrorBoundary if it's not provided, so that
|
|
1371
|
-
* users providing manual route arrays can just specify errorElement
|
|
1372
|
-
*/
|
|
1373
|
-
|
|
1374
|
-
function enhanceManualRouteObjects(routes) {
|
|
1375
|
-
return routes.map(route => {
|
|
1376
|
-
let routeClone = _extends({}, route);
|
|
1377
1394
|
|
|
1378
|
-
|
|
1379
|
-
|
|
1395
|
+
function detectErrorBoundary(route) {
|
|
1396
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1397
|
+
if (route.Component && route.element) {
|
|
1398
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "You should not include both `Component` and `element` on your route - " + "`element` will be ignored.") : void 0;
|
|
1380
1399
|
}
|
|
1381
1400
|
|
|
1382
|
-
if (
|
|
1383
|
-
|
|
1401
|
+
if (route.ErrorBoundary && route.errorElement) {
|
|
1402
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "You should not include both `ErrorBoundary` and `errorElement` on your route - " + "`errorElement` will be ignored.") : void 0;
|
|
1384
1403
|
}
|
|
1404
|
+
} // Note: this check also occurs in createRoutesFromChildren so update
|
|
1405
|
+
// there if you change this
|
|
1385
1406
|
|
|
1386
|
-
|
|
1387
|
-
|
|
1407
|
+
|
|
1408
|
+
return Boolean(route.ErrorBoundary) || Boolean(route.errorElement);
|
|
1388
1409
|
}
|
|
1389
1410
|
|
|
1390
1411
|
function createMemoryRouter(routes, opts) {
|
|
@@ -1395,9 +1416,10 @@ function createMemoryRouter(routes, opts) {
|
|
|
1395
1416
|
initialIndex: opts == null ? void 0 : opts.initialIndex
|
|
1396
1417
|
}),
|
|
1397
1418
|
hydrationData: opts == null ? void 0 : opts.hydrationData,
|
|
1398
|
-
routes
|
|
1419
|
+
routes,
|
|
1420
|
+
detectErrorBoundary
|
|
1399
1421
|
}).initialize();
|
|
1400
1422
|
} ///////////////////////////////////////////////////////////////////////////////
|
|
1401
1423
|
|
|
1402
|
-
export { 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,
|
|
1424
|
+
export { 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, detectErrorBoundary as UNSAFE_detectErrorBoundary, 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 };
|
|
1403
1425
|
//# sourceMappingURL=index.js.map
|