react-router 0.0.0-experimental-cf9637ce → 0.0.0-experimental-e7e9ce6e
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 +18 -0
- package/dist/index.js +32 -26
- package/dist/index.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/react-router.development.js +26 -20
- 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 +25 -19
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v0.0.0-experimental-
|
|
2
|
+
* React Router v0.0.0-experimental-e7e9ce6e
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
11
|
+
import { UNSAFE_invariant, joinPaths, matchPath, UNSAFE_getPathContributingMatches, 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
|
|
|
@@ -245,7 +245,7 @@ const RouteErrorContext = /*#__PURE__*/React.createContext(null);
|
|
|
245
245
|
function useHref(to, {
|
|
246
246
|
relative
|
|
247
247
|
} = {}) {
|
|
248
|
-
!useInRouterContext() ?
|
|
248
|
+
!useInRouterContext() ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
249
249
|
// router loaded. We can help them understand how to avoid that.
|
|
250
250
|
`useHref() may be used only in the context of a <Router> component.`) : void 0;
|
|
251
251
|
let {
|
|
@@ -295,7 +295,7 @@ function useInRouterContext() {
|
|
|
295
295
|
*/
|
|
296
296
|
|
|
297
297
|
function useLocation() {
|
|
298
|
-
!useInRouterContext() ?
|
|
298
|
+
!useInRouterContext() ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
299
299
|
// router loaded. We can help them understand how to avoid that.
|
|
300
300
|
`useLocation() may be used only in the context of a <Router> component.`) : void 0;
|
|
301
301
|
return React.useContext(LocationContext).location;
|
|
@@ -319,7 +319,7 @@ function useNavigationType() {
|
|
|
319
319
|
*/
|
|
320
320
|
|
|
321
321
|
function useMatch(pattern) {
|
|
322
|
-
!useInRouterContext() ?
|
|
322
|
+
!useInRouterContext() ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
323
323
|
// router loaded. We can help them understand how to avoid that.
|
|
324
324
|
`useMatch() may be used only in the context of a <Router> component.`) : void 0;
|
|
325
325
|
let {
|
|
@@ -335,7 +335,7 @@ function useMatch(pattern) {
|
|
|
335
335
|
*/
|
|
336
336
|
|
|
337
337
|
function useNavigate() {
|
|
338
|
-
!useInRouterContext() ?
|
|
338
|
+
!useInRouterContext() ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
339
339
|
// router loaded. We can help them understand how to avoid that.
|
|
340
340
|
`useNavigate() may be used only in the context of a <Router> component.`) : void 0;
|
|
341
341
|
let {
|
|
@@ -445,7 +445,7 @@ function useResolvedPath(to, {
|
|
|
445
445
|
*/
|
|
446
446
|
|
|
447
447
|
function useRoutes(routes, locationArg) {
|
|
448
|
-
!useInRouterContext() ?
|
|
448
|
+
!useInRouterContext() ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
449
449
|
// router loaded. We can help them understand how to avoid that.
|
|
450
450
|
`useRoutes() may be used only in the context of a <Router> component.`) : void 0;
|
|
451
451
|
let {
|
|
@@ -491,7 +491,7 @@ function useRoutes(routes, locationArg) {
|
|
|
491
491
|
|
|
492
492
|
if (locationArg) {
|
|
493
493
|
let parsedLocationArg = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
|
494
|
-
!(parentPathnameBase === "/" || parsedLocationArg.pathname?.startsWith(parentPathnameBase)) ?
|
|
494
|
+
!(parentPathnameBase === "/" || parsedLocationArg.pathname?.startsWith(parentPathnameBase)) ? UNSAFE_invariant(false, `When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, ` + `the location pathname must begin with the portion of the URL pathname that was ` + `matched by all parent routes. The current pathname base is "${parentPathnameBase}" ` + `but pathname "${parsedLocationArg.pathname}" was given in the \`location\` prop.`) : void 0;
|
|
495
495
|
location = parsedLocationArg;
|
|
496
496
|
} else {
|
|
497
497
|
location = locationFromContext;
|
|
@@ -660,7 +660,7 @@ function _renderMatches(matches, parentMatches = [], dataRouterState) {
|
|
|
660
660
|
|
|
661
661
|
if (errors != null) {
|
|
662
662
|
let errorIndex = renderedMatches.findIndex(m => m.route.id && errors?.[m.route.id]);
|
|
663
|
-
!(errorIndex >= 0) ?
|
|
663
|
+
!(errorIndex >= 0) ? UNSAFE_invariant(false, `Could not find a matching route for the current errors: ${errors}`) : void 0;
|
|
664
664
|
renderedMatches = renderedMatches.slice(0, Math.min(renderedMatches.length, errorIndex + 1));
|
|
665
665
|
}
|
|
666
666
|
|
|
@@ -718,26 +718,26 @@ function getDataRouterConsoleError(hookName) {
|
|
|
718
718
|
|
|
719
719
|
function useDataRouterContext(hookName) {
|
|
720
720
|
let ctx = React.useContext(DataRouterContext);
|
|
721
|
-
!ctx ?
|
|
721
|
+
!ctx ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
|
722
722
|
return ctx;
|
|
723
723
|
}
|
|
724
724
|
|
|
725
725
|
function useDataRouterState(hookName) {
|
|
726
726
|
let state = React.useContext(DataRouterStateContext);
|
|
727
|
-
!state ?
|
|
727
|
+
!state ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
|
728
728
|
return state;
|
|
729
729
|
}
|
|
730
730
|
|
|
731
731
|
function useRouteContext(hookName) {
|
|
732
732
|
let route = React.useContext(RouteContext);
|
|
733
|
-
!route ?
|
|
733
|
+
!route ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
|
734
734
|
return route;
|
|
735
735
|
}
|
|
736
736
|
|
|
737
737
|
function useCurrentRouteId(hookName) {
|
|
738
738
|
let route = useRouteContext(hookName);
|
|
739
739
|
let thisRoute = route.matches[route.matches.length - 1];
|
|
740
|
-
!thisRoute.route.id ?
|
|
740
|
+
!thisRoute.route.id ? UNSAFE_invariant(false, `${hookName} can only be used on routes that contain a unique "id"`) : void 0;
|
|
741
741
|
return thisRoute.route.id;
|
|
742
742
|
}
|
|
743
743
|
/**
|
|
@@ -820,7 +820,7 @@ function useRouteLoaderData(routeId) {
|
|
|
820
820
|
function useActionData() {
|
|
821
821
|
let state = useDataRouterState(DataRouterStateHook.UseActionData);
|
|
822
822
|
let route = React.useContext(RouteContext);
|
|
823
|
-
!route ?
|
|
823
|
+
!route ? UNSAFE_invariant(false, `useActionData must be used inside a RouteContext`) : void 0;
|
|
824
824
|
return Object.values(state?.actionData || {})[0];
|
|
825
825
|
}
|
|
826
826
|
/**
|
|
@@ -993,7 +993,7 @@ function Navigate({
|
|
|
993
993
|
state,
|
|
994
994
|
relative
|
|
995
995
|
}) {
|
|
996
|
-
!useInRouterContext() ?
|
|
996
|
+
!useInRouterContext() ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of
|
|
997
997
|
// the router loaded. We can help them understand how to avoid that.
|
|
998
998
|
`<Navigate> may be used only in the context of a <Router> component.`) : void 0;
|
|
999
999
|
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.`) ;
|
|
@@ -1031,7 +1031,7 @@ function Outlet(props) {
|
|
|
1031
1031
|
*/
|
|
1032
1032
|
|
|
1033
1033
|
function Route(_props) {
|
|
1034
|
-
|
|
1034
|
+
UNSAFE_invariant(false, `A <Route> is only ever to be used as the child of <Routes> element, ` + `never rendered directly. Please wrap your <Route> in a <Routes>.`) ;
|
|
1035
1035
|
}
|
|
1036
1036
|
/**
|
|
1037
1037
|
* Provides location context for the rest of the app.
|
|
@@ -1051,9 +1051,15 @@ function Router({
|
|
|
1051
1051
|
navigator,
|
|
1052
1052
|
static: staticProp = false
|
|
1053
1053
|
}) {
|
|
1054
|
-
|
|
1054
|
+
// Temporarily commented out for testing of <CompatRouter> nested in a
|
|
1055
|
+
// <RouterProvider>
|
|
1056
|
+
// invariant(
|
|
1057
|
+
// !useInRouterContext(),
|
|
1058
|
+
// `You cannot render a <Router> inside another <Router>.` +
|
|
1059
|
+
// ` You should never have more than one in your app.`
|
|
1060
|
+
// );
|
|
1061
|
+
// Preserve trailing slashes on basename, so we can let the user control
|
|
1055
1062
|
// the enforcement of trailing slashes throughout the app
|
|
1056
|
-
|
|
1057
1063
|
let basename = basenameProp.replace(/^\/*/, "/");
|
|
1058
1064
|
let navigationContext = React.useMemo(() => ({
|
|
1059
1065
|
basename,
|
|
@@ -1283,8 +1289,8 @@ function createRoutesFromChildren(children, parentPath = []) {
|
|
|
1283
1289
|
return;
|
|
1284
1290
|
}
|
|
1285
1291
|
|
|
1286
|
-
!(element.type === Route) ?
|
|
1287
|
-
!(!element.props.index || !element.props.children) ?
|
|
1292
|
+
!(element.type === Route) ? UNSAFE_invariant(false, `[${typeof element.type === "string" ? element.type : element.type.name}] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>`) : void 0;
|
|
1293
|
+
!(!element.props.index || !element.props.children) ? UNSAFE_invariant(false, "An index route cannot have child routes.") : void 0;
|
|
1288
1294
|
let treePath = [...parentPath, index];
|
|
1289
1295
|
let route = {
|
|
1290
1296
|
id: element.props.id || treePath.join("-"),
|