react-router 6.4.1 → 6.4.2-pre.1
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 +16 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -17
- package/dist/index.js.map +1 -1
- package/dist/lib/components.d.ts +27 -27
- package/dist/lib/context.d.ts +28 -4
- package/dist/main.js +1 -1
- package/dist/react-router.development.js +33 -17
- 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 +33 -17
- 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/dist/lib/context.d.ts
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AgnosticRouteMatch, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, History, Location, Router, StaticHandlerContext, To, TrackedPromise } from "@remix-run/router";
|
|
3
3
|
import type { Action as NavigationType } from "@remix-run/router";
|
|
4
|
-
export interface
|
|
4
|
+
export interface IndexRouteObject {
|
|
5
|
+
caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
|
|
6
|
+
path?: AgnosticIndexRouteObject["path"];
|
|
7
|
+
id?: AgnosticIndexRouteObject["id"];
|
|
8
|
+
loader?: AgnosticIndexRouteObject["loader"];
|
|
9
|
+
action?: AgnosticIndexRouteObject["action"];
|
|
10
|
+
hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
|
|
11
|
+
shouldRevalidate?: AgnosticIndexRouteObject["shouldRevalidate"];
|
|
12
|
+
handle?: AgnosticIndexRouteObject["handle"];
|
|
13
|
+
index: true;
|
|
14
|
+
children?: undefined;
|
|
15
|
+
element?: React.ReactNode | null;
|
|
16
|
+
errorElement?: React.ReactNode | null;
|
|
17
|
+
}
|
|
18
|
+
export interface NonIndexRouteObject {
|
|
19
|
+
caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
|
|
20
|
+
path?: AgnosticNonIndexRouteObject["path"];
|
|
21
|
+
id?: AgnosticNonIndexRouteObject["id"];
|
|
22
|
+
loader?: AgnosticNonIndexRouteObject["loader"];
|
|
23
|
+
action?: AgnosticNonIndexRouteObject["action"];
|
|
24
|
+
hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
|
|
25
|
+
shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"];
|
|
26
|
+
handle?: AgnosticNonIndexRouteObject["handle"];
|
|
27
|
+
index?: false;
|
|
5
28
|
children?: RouteObject[];
|
|
6
29
|
element?: React.ReactNode | null;
|
|
7
30
|
errorElement?: React.ReactNode | null;
|
|
8
31
|
}
|
|
9
|
-
export
|
|
32
|
+
export declare type RouteObject = IndexRouteObject | NonIndexRouteObject;
|
|
33
|
+
export declare type DataRouteObject = RouteObject & {
|
|
10
34
|
children?: DataRouteObject[];
|
|
11
35
|
id: string;
|
|
12
|
-
}
|
|
36
|
+
};
|
|
13
37
|
export interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> extends AgnosticRouteMatch<ParamKey, RouteObjectType> {
|
|
14
38
|
}
|
|
15
39
|
export interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
|
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v6.4.1
|
|
2
|
+
* React Router v6.4.2-pre.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -710,18 +710,34 @@ function _renderMatches(matches, parentMatches = [], dataRouterState) {
|
|
|
710
710
|
var DataRouterHook;
|
|
711
711
|
|
|
712
712
|
(function (DataRouterHook) {
|
|
713
|
-
DataRouterHook["UseLoaderData"] = "useLoaderData";
|
|
714
|
-
DataRouterHook["UseActionData"] = "useActionData";
|
|
715
|
-
DataRouterHook["UseRouteError"] = "useRouteError";
|
|
716
|
-
DataRouterHook["UseNavigation"] = "useNavigation";
|
|
717
|
-
DataRouterHook["UseRouteLoaderData"] = "useRouteLoaderData";
|
|
718
|
-
DataRouterHook["UseMatches"] = "useMatches";
|
|
719
713
|
DataRouterHook["UseRevalidator"] = "useRevalidator";
|
|
720
714
|
})(DataRouterHook || (DataRouterHook = {}));
|
|
721
715
|
|
|
716
|
+
var DataRouterStateHook;
|
|
717
|
+
|
|
718
|
+
(function (DataRouterStateHook) {
|
|
719
|
+
DataRouterStateHook["UseLoaderData"] = "useLoaderData";
|
|
720
|
+
DataRouterStateHook["UseActionData"] = "useActionData";
|
|
721
|
+
DataRouterStateHook["UseRouteError"] = "useRouteError";
|
|
722
|
+
DataRouterStateHook["UseNavigation"] = "useNavigation";
|
|
723
|
+
DataRouterStateHook["UseRouteLoaderData"] = "useRouteLoaderData";
|
|
724
|
+
DataRouterStateHook["UseMatches"] = "useMatches";
|
|
725
|
+
DataRouterStateHook["UseRevalidator"] = "useRevalidator";
|
|
726
|
+
})(DataRouterStateHook || (DataRouterStateHook = {}));
|
|
727
|
+
|
|
728
|
+
function getDataRouterConsoleError(hookName) {
|
|
729
|
+
return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
function useDataRouterContext(hookName) {
|
|
733
|
+
let ctx = React.useContext(DataRouterContext);
|
|
734
|
+
!ctx ? invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
|
735
|
+
return ctx;
|
|
736
|
+
}
|
|
737
|
+
|
|
722
738
|
function useDataRouterState(hookName) {
|
|
723
739
|
let state = React.useContext(DataRouterStateContext);
|
|
724
|
-
!state ? invariant(false,
|
|
740
|
+
!state ? invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
|
725
741
|
return state;
|
|
726
742
|
}
|
|
727
743
|
/**
|
|
@@ -731,7 +747,7 @@ function useDataRouterState(hookName) {
|
|
|
731
747
|
|
|
732
748
|
|
|
733
749
|
function useNavigation() {
|
|
734
|
-
let state = useDataRouterState(
|
|
750
|
+
let state = useDataRouterState(DataRouterStateHook.UseNavigation);
|
|
735
751
|
return state.navigation;
|
|
736
752
|
}
|
|
737
753
|
/**
|
|
@@ -740,9 +756,8 @@ function useNavigation() {
|
|
|
740
756
|
*/
|
|
741
757
|
|
|
742
758
|
function useRevalidator() {
|
|
743
|
-
let dataRouterContext =
|
|
744
|
-
|
|
745
|
-
let state = useDataRouterState(DataRouterHook.UseRevalidator);
|
|
759
|
+
let dataRouterContext = useDataRouterContext(DataRouterHook.UseRevalidator);
|
|
760
|
+
let state = useDataRouterState(DataRouterStateHook.UseRevalidator);
|
|
746
761
|
return {
|
|
747
762
|
revalidate: dataRouterContext.router.revalidate,
|
|
748
763
|
state: state.revalidation
|
|
@@ -757,7 +772,7 @@ function useMatches() {
|
|
|
757
772
|
let {
|
|
758
773
|
matches,
|
|
759
774
|
loaderData
|
|
760
|
-
} = useDataRouterState(
|
|
775
|
+
} = useDataRouterState(DataRouterStateHook.UseMatches);
|
|
761
776
|
return React.useMemo(() => matches.map(match => {
|
|
762
777
|
let {
|
|
763
778
|
pathname,
|
|
@@ -780,7 +795,7 @@ function useMatches() {
|
|
|
780
795
|
*/
|
|
781
796
|
|
|
782
797
|
function useLoaderData() {
|
|
783
|
-
let state = useDataRouterState(
|
|
798
|
+
let state = useDataRouterState(DataRouterStateHook.UseLoaderData);
|
|
784
799
|
let route = React.useContext(RouteContext);
|
|
785
800
|
!route ? invariant(false, `useLoaderData must be used inside a RouteContext`) : void 0;
|
|
786
801
|
let thisRoute = route.matches[route.matches.length - 1];
|
|
@@ -792,7 +807,7 @@ function useLoaderData() {
|
|
|
792
807
|
*/
|
|
793
808
|
|
|
794
809
|
function useRouteLoaderData(routeId) {
|
|
795
|
-
let state = useDataRouterState(
|
|
810
|
+
let state = useDataRouterState(DataRouterStateHook.UseRouteLoaderData);
|
|
796
811
|
return state.loaderData[routeId];
|
|
797
812
|
}
|
|
798
813
|
/**
|
|
@@ -800,7 +815,7 @@ function useRouteLoaderData(routeId) {
|
|
|
800
815
|
*/
|
|
801
816
|
|
|
802
817
|
function useActionData() {
|
|
803
|
-
let state = useDataRouterState(
|
|
818
|
+
let state = useDataRouterState(DataRouterStateHook.UseActionData);
|
|
804
819
|
let route = React.useContext(RouteContext);
|
|
805
820
|
!route ? invariant(false, `useActionData must be used inside a RouteContext`) : void 0;
|
|
806
821
|
return Object.values(state?.actionData || {})[0];
|
|
@@ -813,7 +828,7 @@ function useActionData() {
|
|
|
813
828
|
|
|
814
829
|
function useRouteError() {
|
|
815
830
|
let error = React.useContext(RouteErrorContext);
|
|
816
|
-
let state = useDataRouterState(
|
|
831
|
+
let state = useDataRouterState(DataRouterStateHook.UseRouteError);
|
|
817
832
|
let route = React.useContext(RouteContext);
|
|
818
833
|
let thisRoute = route.matches[route.matches.length - 1]; // If this was a render error, we put it in a RouteError context inside
|
|
819
834
|
// of RenderErrorBoundary
|
|
@@ -1245,6 +1260,7 @@ function createRoutesFromChildren(children, parentPath = []) {
|
|
|
1245
1260
|
}
|
|
1246
1261
|
|
|
1247
1262
|
!(element.type === Route) ? 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;
|
|
1263
|
+
!(!element.props.index || !element.props.children) ? invariant(false, "An index route cannot have child routes.") : void 0;
|
|
1248
1264
|
let treePath = [...parentPath, index];
|
|
1249
1265
|
let route = {
|
|
1250
1266
|
id: element.props.id || treePath.join("-"),
|