react-router 6.4.1 → 6.4.2-pre.0
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 +10 -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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# `react-router`
|
|
2
2
|
|
|
3
|
+
## 6.4.2-pre.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix: throw error when receiving invalid path object ([#9375](https://github.com/remix-run/react-router/pull/9375))
|
|
8
|
+
- docs: Enhance console error messages for invalid usage of data router hooks ([#9311](https://github.com/remix-run/react-router/pull/9311))
|
|
9
|
+
- fix: Strengthen `RouteObject`/`RouteProps` types and throw on `index` routes with `children` ([#9366](https://github.com/remix-run/react-router/pull/9366))
|
|
10
|
+
- Updated dependencies:
|
|
11
|
+
- `@remix-run/router@1.0.2-pre.0`
|
|
12
|
+
|
|
3
13
|
## 6.4.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import type { ActionFunction, ActionFunctionArgs, Fetcher, HydrationState, JsonF
|
|
|
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
4
|
import { enhanceManualRouteObjects, createRoutesFromChildren, renderMatches, Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes } from "./lib/components";
|
|
5
|
-
import type { DataRouteMatch, DataRouteObject, Navigator, NavigateOptions, RouteMatch, RouteObject, RelativeRoutingType } from "./lib/context";
|
|
5
|
+
import type { DataRouteMatch, DataRouteObject, IndexRouteObject, Navigator, NavigateOptions, NonIndexRouteObject, RouteMatch, RouteObject, RelativeRoutingType } from "./lib/context";
|
|
6
6
|
import { DataRouterContext, DataRouterStateContext, DataStaticRouterContext, LocationContext, NavigationContext, RouteContext } from "./lib/context";
|
|
7
7
|
import type { NavigateFunction } from "./lib/hooks";
|
|
8
8
|
import { useHref, useInRouterContext, useLocation, useMatch, useNavigationType, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useActionData, useAsyncError, useAsyncValue, useLoaderData, useMatches, useNavigation, useRevalidator, useRouteError, useRouteLoaderData } 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, ActionFunctionArgs, AwaitProps, DataRouteMatch, DataRouteObject, Fetcher, Hash, IndexRouteProps, JsonFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, 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, 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, };
|
|
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, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, };
|
|
14
14
|
export declare function createMemoryRouter(routes: RouteObject[], opts?: {
|
|
15
15
|
basename?: string;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v6.4.
|
|
2
|
+
* React Router v6.4.2-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -743,18 +743,34 @@ function _renderMatches(matches, parentMatches, dataRouterState) {
|
|
|
743
743
|
var DataRouterHook;
|
|
744
744
|
|
|
745
745
|
(function (DataRouterHook) {
|
|
746
|
-
DataRouterHook["UseLoaderData"] = "useLoaderData";
|
|
747
|
-
DataRouterHook["UseActionData"] = "useActionData";
|
|
748
|
-
DataRouterHook["UseRouteError"] = "useRouteError";
|
|
749
|
-
DataRouterHook["UseNavigation"] = "useNavigation";
|
|
750
|
-
DataRouterHook["UseRouteLoaderData"] = "useRouteLoaderData";
|
|
751
|
-
DataRouterHook["UseMatches"] = "useMatches";
|
|
752
746
|
DataRouterHook["UseRevalidator"] = "useRevalidator";
|
|
753
747
|
})(DataRouterHook || (DataRouterHook = {}));
|
|
754
748
|
|
|
749
|
+
var DataRouterStateHook;
|
|
750
|
+
|
|
751
|
+
(function (DataRouterStateHook) {
|
|
752
|
+
DataRouterStateHook["UseLoaderData"] = "useLoaderData";
|
|
753
|
+
DataRouterStateHook["UseActionData"] = "useActionData";
|
|
754
|
+
DataRouterStateHook["UseRouteError"] = "useRouteError";
|
|
755
|
+
DataRouterStateHook["UseNavigation"] = "useNavigation";
|
|
756
|
+
DataRouterStateHook["UseRouteLoaderData"] = "useRouteLoaderData";
|
|
757
|
+
DataRouterStateHook["UseMatches"] = "useMatches";
|
|
758
|
+
DataRouterStateHook["UseRevalidator"] = "useRevalidator";
|
|
759
|
+
})(DataRouterStateHook || (DataRouterStateHook = {}));
|
|
760
|
+
|
|
761
|
+
function getDataRouterConsoleError(hookName) {
|
|
762
|
+
return hookName + " must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.";
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
function useDataRouterContext(hookName) {
|
|
766
|
+
let ctx = React.useContext(DataRouterContext);
|
|
767
|
+
!ctx ? process.env.NODE_ENV !== "production" ? invariant(false, getDataRouterConsoleError(hookName)) : invariant(false) : void 0;
|
|
768
|
+
return ctx;
|
|
769
|
+
}
|
|
770
|
+
|
|
755
771
|
function useDataRouterState(hookName) {
|
|
756
772
|
let state = React.useContext(DataRouterStateContext);
|
|
757
|
-
!state ? process.env.NODE_ENV !== "production" ? invariant(false, hookName
|
|
773
|
+
!state ? process.env.NODE_ENV !== "production" ? invariant(false, getDataRouterConsoleError(hookName)) : invariant(false) : void 0;
|
|
758
774
|
return state;
|
|
759
775
|
}
|
|
760
776
|
/**
|
|
@@ -764,7 +780,7 @@ function useDataRouterState(hookName) {
|
|
|
764
780
|
|
|
765
781
|
|
|
766
782
|
function useNavigation() {
|
|
767
|
-
let state = useDataRouterState(
|
|
783
|
+
let state = useDataRouterState(DataRouterStateHook.UseNavigation);
|
|
768
784
|
return state.navigation;
|
|
769
785
|
}
|
|
770
786
|
/**
|
|
@@ -773,9 +789,8 @@ function useNavigation() {
|
|
|
773
789
|
*/
|
|
774
790
|
|
|
775
791
|
function useRevalidator() {
|
|
776
|
-
let dataRouterContext =
|
|
777
|
-
|
|
778
|
-
let state = useDataRouterState(DataRouterHook.UseRevalidator);
|
|
792
|
+
let dataRouterContext = useDataRouterContext(DataRouterHook.UseRevalidator);
|
|
793
|
+
let state = useDataRouterState(DataRouterStateHook.UseRevalidator);
|
|
779
794
|
return {
|
|
780
795
|
revalidate: dataRouterContext.router.revalidate,
|
|
781
796
|
state: state.revalidation
|
|
@@ -790,7 +805,7 @@ function useMatches() {
|
|
|
790
805
|
let {
|
|
791
806
|
matches,
|
|
792
807
|
loaderData
|
|
793
|
-
} = useDataRouterState(
|
|
808
|
+
} = useDataRouterState(DataRouterStateHook.UseMatches);
|
|
794
809
|
return React.useMemo(() => matches.map(match => {
|
|
795
810
|
let {
|
|
796
811
|
pathname,
|
|
@@ -813,7 +828,7 @@ function useMatches() {
|
|
|
813
828
|
*/
|
|
814
829
|
|
|
815
830
|
function useLoaderData() {
|
|
816
|
-
let state = useDataRouterState(
|
|
831
|
+
let state = useDataRouterState(DataRouterStateHook.UseLoaderData);
|
|
817
832
|
let route = React.useContext(RouteContext);
|
|
818
833
|
!route ? process.env.NODE_ENV !== "production" ? invariant(false, "useLoaderData must be used inside a RouteContext") : invariant(false) : void 0;
|
|
819
834
|
let thisRoute = route.matches[route.matches.length - 1];
|
|
@@ -825,7 +840,7 @@ function useLoaderData() {
|
|
|
825
840
|
*/
|
|
826
841
|
|
|
827
842
|
function useRouteLoaderData(routeId) {
|
|
828
|
-
let state = useDataRouterState(
|
|
843
|
+
let state = useDataRouterState(DataRouterStateHook.UseRouteLoaderData);
|
|
829
844
|
return state.loaderData[routeId];
|
|
830
845
|
}
|
|
831
846
|
/**
|
|
@@ -833,7 +848,7 @@ function useRouteLoaderData(routeId) {
|
|
|
833
848
|
*/
|
|
834
849
|
|
|
835
850
|
function useActionData() {
|
|
836
|
-
let state = useDataRouterState(
|
|
851
|
+
let state = useDataRouterState(DataRouterStateHook.UseActionData);
|
|
837
852
|
let route = React.useContext(RouteContext);
|
|
838
853
|
!route ? process.env.NODE_ENV !== "production" ? invariant(false, "useActionData must be used inside a RouteContext") : invariant(false) : void 0;
|
|
839
854
|
return Object.values((state == null ? void 0 : state.actionData) || {})[0];
|
|
@@ -848,7 +863,7 @@ function useRouteError() {
|
|
|
848
863
|
var _state$errors;
|
|
849
864
|
|
|
850
865
|
let error = React.useContext(RouteErrorContext);
|
|
851
|
-
let state = useDataRouterState(
|
|
866
|
+
let state = useDataRouterState(DataRouterStateHook.UseRouteError);
|
|
852
867
|
let route = React.useContext(RouteContext);
|
|
853
868
|
let thisRoute = route.matches[route.matches.length - 1]; // If this was a render error, we put it in a RouteError context inside
|
|
854
869
|
// of RenderErrorBoundary
|
|
@@ -1290,6 +1305,7 @@ function createRoutesFromChildren(children, parentPath) {
|
|
|
1290
1305
|
}
|
|
1291
1306
|
|
|
1292
1307
|
!(element.type === Route) ? process.env.NODE_ENV !== "production" ? 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>") : invariant(false) : void 0;
|
|
1308
|
+
!(!element.props.index || !element.props.children) ? process.env.NODE_ENV !== "production" ? invariant(false, "An index route cannot have child routes.") : invariant(false) : void 0;
|
|
1293
1309
|
let treePath = [...parentPath, index];
|
|
1294
1310
|
let route = {
|
|
1295
1311
|
id: element.props.id || treePath.join("-"),
|