react-router-dom 6.8.2 → 6.9.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 +104 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +10 -27
- package/dist/index.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/react-router-dom.development.js +10 -27
- package/dist/react-router-dom.development.js.map +1 -1
- package/dist/react-router-dom.production.min.js +2 -2
- package/dist/react-router-dom.production.min.js.map +1 -1
- package/dist/server.d.ts +4 -1
- package/dist/server.js +10 -17
- package/dist/server.mjs +12 -20
- package/dist/umd/react-router-dom.development.js +7 -28
- package/dist/umd/react-router-dom.development.js.map +1 -1
- package/dist/umd/react-router-dom.production.min.js +2 -2
- package/dist/umd/react-router-dom.production.min.js.map +1 -1
- package/package.json +3 -3
- package/server.d.ts +4 -1
- package/server.js +10 -17
- package/server.mjs +12 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,109 @@
|
|
|
1
1
|
# `react-router-dom`
|
|
2
2
|
|
|
3
|
+
## 6.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- React Router now supports an alternative way to define your route `element` and `errorElement` fields as React Components instead of React Elements. You can instead pass a React Component to the new `Component` and `ErrorBoundary` fields if you choose. There is no functional difference between the two, so use whichever approach you prefer 😀. You shouldn't be defining both, but if you do `Component`/`ErrorBoundary` will "win". ([#10045](https://github.com/remix-run/react-router/pull/10045))
|
|
8
|
+
|
|
9
|
+
**Example JSON Syntax**
|
|
10
|
+
|
|
11
|
+
```jsx
|
|
12
|
+
// Both of these work the same:
|
|
13
|
+
const elementRoutes = [{
|
|
14
|
+
path: '/',
|
|
15
|
+
element: <Home />,
|
|
16
|
+
errorElement: <HomeError />,
|
|
17
|
+
}]
|
|
18
|
+
|
|
19
|
+
const componentRoutes = [{
|
|
20
|
+
path: '/',
|
|
21
|
+
Component: Home,
|
|
22
|
+
ErrorBoundary: HomeError,
|
|
23
|
+
}]
|
|
24
|
+
|
|
25
|
+
function Home() { ... }
|
|
26
|
+
function HomeError() { ... }
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Example JSX Syntax**
|
|
30
|
+
|
|
31
|
+
```jsx
|
|
32
|
+
// Both of these work the same:
|
|
33
|
+
const elementRoutes = createRoutesFromElements(
|
|
34
|
+
<Route path='/' element={<Home />} errorElement={<HomeError /> } />
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const componentRoutes = createRoutesFromElements(
|
|
38
|
+
<Route path='/' Component={Home} ErrorBoundary={HomeError} />
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
function Home() { ... }
|
|
42
|
+
function HomeError() { ... }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- **Introducing Lazy Route Modules!** ([#10045](https://github.com/remix-run/react-router/pull/10045))
|
|
46
|
+
|
|
47
|
+
In order to keep your application bundles small and support code-splitting of your routes, we've introduced a new `lazy()` route property. This is an async function that resolves the non-route-matching portions of your route definition (`loader`, `action`, `element`/`Component`, `errorElement`/`ErrorBoundary`, `shouldRevalidate`, `handle`).
|
|
48
|
+
|
|
49
|
+
Lazy routes are resolved on initial load and during the `loading` or `submitting` phase of a navigation or fetcher call. You cannot lazily define route-matching properties (`path`, `index`, `children`) since we only execute your lazy route functions after we've matched known routes.
|
|
50
|
+
|
|
51
|
+
Your `lazy` functions will typically return the result of a dynamic import.
|
|
52
|
+
|
|
53
|
+
```jsx
|
|
54
|
+
// In this example, we assume most folks land on the homepage so we include that
|
|
55
|
+
// in our critical-path bundle, but then we lazily load modules for /a and /b so
|
|
56
|
+
// they don't load until the user navigates to those routes
|
|
57
|
+
let routes = createRoutesFromElements(
|
|
58
|
+
<Route path="/" element={<Layout />}>
|
|
59
|
+
<Route index element={<Home />} />
|
|
60
|
+
<Route path="a" lazy={() => import("./a")} />
|
|
61
|
+
<Route path="b" lazy={() => import("./b")} />
|
|
62
|
+
</Route>
|
|
63
|
+
);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Then in your lazy route modules, export the properties you want defined for the route:
|
|
67
|
+
|
|
68
|
+
```jsx
|
|
69
|
+
export async function loader({ request }) {
|
|
70
|
+
let data = await fetchData(request);
|
|
71
|
+
return json(data);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Export a `Component` directly instead of needing to create a React Element from it
|
|
75
|
+
export function Component() {
|
|
76
|
+
let data = useLoaderData();
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<>
|
|
80
|
+
<h1>You made it!</h1>
|
|
81
|
+
<p>{data}</p>
|
|
82
|
+
</>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Export an `ErrorBoundary` directly instead of needing to create a React Element from it
|
|
87
|
+
export function ErrorBoundary() {
|
|
88
|
+
let error = useRouteError();
|
|
89
|
+
return isRouteErrorResponse(error) ? (
|
|
90
|
+
<h1>
|
|
91
|
+
{error.status} {error.statusText}
|
|
92
|
+
</h1>
|
|
93
|
+
) : (
|
|
94
|
+
<h1>{error.message || error}</h1>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
An example of this in action can be found in the [`examples/lazy-loading-router-provider`](https://github.com/remix-run/react-router/tree/main/examples/lazy-loading-router-provider) directory of the repository.
|
|
100
|
+
|
|
101
|
+
🙌 Huge thanks to @rossipedia for the [Initial Proposal](https://github.com/remix-run/react-router/discussions/9826) and [POC Implementation](https://github.com/remix-run/react-router/pull/9830).
|
|
102
|
+
|
|
103
|
+
- Updated dependencies:
|
|
104
|
+
- `react-router@6.9.0`
|
|
105
|
+
- `@remix-run/router@1.4.0`
|
|
106
|
+
|
|
3
107
|
## 6.8.2
|
|
4
108
|
|
|
5
109
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ import type { SubmitOptions, ParamKeyValuePair, URLSearchParamsInit } from "./do
|
|
|
9
9
|
import { createSearchParams } from "./dom";
|
|
10
10
|
export type { FormEncType, FormMethod, GetScrollRestorationKeyFunction, ParamKeyValuePair, SubmitOptions, URLSearchParamsInit, };
|
|
11
11
|
export { createSearchParams };
|
|
12
|
-
export type { ActionFunction, ActionFunctionArgs, AwaitProps, unstable_Blocker, 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, } from "react-router";
|
|
12
|
+
export type { ActionFunction, ActionFunctionArgs, AwaitProps, unstable_Blocker, 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, } from "react-router";
|
|
13
13
|
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, unstable_useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, } from "react-router";
|
|
14
14
|
/** @internal */
|
|
15
|
-
export { UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext,
|
|
15
|
+
export { UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, } from "react-router";
|
|
16
16
|
declare global {
|
|
17
17
|
var __staticRouterHydrationData: HydrationState | undefined;
|
|
18
18
|
}
|
|
@@ -221,6 +221,7 @@ declare function useScrollRestoration({ getKey, storageKey, }?: {
|
|
|
221
221
|
getKey?: GetScrollRestorationKeyFunction;
|
|
222
222
|
storageKey?: string;
|
|
223
223
|
}): void;
|
|
224
|
+
export { useScrollRestoration as UNSAFE_useScrollRestoration };
|
|
224
225
|
/**
|
|
225
226
|
* Setup a callback to be fired on the window's `beforeunload` event. This is
|
|
226
227
|
* useful for saving some data to `window.localStorage` just before the page
|
|
@@ -245,4 +246,3 @@ declare function usePrompt({ when, message }: {
|
|
|
245
246
|
message: string;
|
|
246
247
|
}): void;
|
|
247
248
|
export { usePrompt as unstable_usePrompt };
|
|
248
|
-
export { useScrollRestoration as UNSAFE_useScrollRestoration };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router DOM v6.
|
|
2
|
+
* React Router DOM v6.9.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import * as React from 'react';
|
|
12
|
-
import {
|
|
13
|
-
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext,
|
|
14
|
-
import { createRouter, createBrowserHistory, createHashHistory, ErrorResponse, stripBasename, UNSAFE_invariant, joinPaths } from '@remix-run/router';
|
|
12
|
+
import { UNSAFE_detectErrorBoundary, Router, UNSAFE_NavigationContext, useHref, useResolvedPath, useLocation, UNSAFE_DataRouterStateContext, useNavigate, createPath, UNSAFE_RouteContext, useMatches, useNavigation, unstable_useBlocker, UNSAFE_DataRouterContext } from 'react-router';
|
|
13
|
+
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, unstable_useBlocker, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes } from 'react-router';
|
|
14
|
+
import { createRouter, createBrowserHistory, createHashHistory, ErrorResponse, stripBasename, UNSAFE_warning, UNSAFE_invariant, joinPaths } from '@remix-run/router';
|
|
15
15
|
|
|
16
16
|
function _extends() {
|
|
17
17
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
@@ -200,7 +200,8 @@ function createBrowserRouter(routes, opts) {
|
|
|
200
200
|
window: opts == null ? void 0 : opts.window
|
|
201
201
|
}),
|
|
202
202
|
hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
|
|
203
|
-
routes
|
|
203
|
+
routes,
|
|
204
|
+
detectErrorBoundary: UNSAFE_detectErrorBoundary
|
|
204
205
|
}).initialize();
|
|
205
206
|
}
|
|
206
207
|
function createHashRouter(routes, opts) {
|
|
@@ -210,7 +211,8 @@ function createHashRouter(routes, opts) {
|
|
|
210
211
|
window: opts == null ? void 0 : opts.window
|
|
211
212
|
}),
|
|
212
213
|
hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
|
|
213
|
-
routes
|
|
214
|
+
routes,
|
|
215
|
+
detectErrorBoundary: UNSAFE_detectErrorBoundary
|
|
214
216
|
}).initialize();
|
|
215
217
|
}
|
|
216
218
|
|
|
@@ -661,7 +663,7 @@ function useLinkClickHandler(to, _temp) {
|
|
|
661
663
|
*/
|
|
662
664
|
|
|
663
665
|
function useSearchParams(defaultInit) {
|
|
664
|
-
process.env.NODE_ENV !== "production" ?
|
|
666
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(typeof URLSearchParams !== "undefined", "You cannot use the `useSearchParams` hook in a browser that does not " + "support the URLSearchParams API. If you need to support Internet " + "Explorer 11, we recommend you load a polyfill such as " + "https://github.com/ungap/url-search-params\n\n" + "If you're unsure how to load polyfills, we recommend you check out " + "https://polyfill.io/v3/ which provides some recommendations about how " + "to load polyfills only for users that need them, instead of for every " + "user.") : void 0;
|
|
665
667
|
let defaultSearchParamsRef = React.useRef(createSearchParams(defaultInit));
|
|
666
668
|
let hasSetSearchParamsRef = React.useRef(false);
|
|
667
669
|
let location = useLocation();
|
|
@@ -951,7 +953,6 @@ function useScrollRestoration(_temp3) {
|
|
|
951
953
|
* `React.useCallback()`.
|
|
952
954
|
*/
|
|
953
955
|
|
|
954
|
-
|
|
955
956
|
function useBeforeUnload(callback, options) {
|
|
956
957
|
let {
|
|
957
958
|
capture
|
|
@@ -1022,25 +1023,7 @@ function usePrompt(_ref8) {
|
|
|
1022
1023
|
}
|
|
1023
1024
|
}, [blocker, message]);
|
|
1024
1025
|
}
|
|
1025
|
-
|
|
1026
|
-
//#region Utils
|
|
1027
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
1028
|
-
|
|
1029
|
-
function warning(cond, message) {
|
|
1030
|
-
if (!cond) {
|
|
1031
|
-
// eslint-disable-next-line no-console
|
|
1032
|
-
if (typeof console !== "undefined") console.warn(message);
|
|
1033
|
-
|
|
1034
|
-
try {
|
|
1035
|
-
// Welcome to debugging React Router!
|
|
1036
|
-
//
|
|
1037
|
-
// This error is thrown as a convenience so you can more easily
|
|
1038
|
-
// find the source for a warning that appears in the console by
|
|
1039
|
-
// enabling "pause on exceptions" in your JavaScript debugger.
|
|
1040
|
-
throw new Error(message); // eslint-disable-next-line no-empty
|
|
1041
|
-
} catch (e) {}
|
|
1042
|
-
}
|
|
1043
|
-
} //#endregion
|
|
1026
|
+
//#endregion
|
|
1044
1027
|
|
|
1045
1028
|
export { BrowserRouter, Form, HashRouter, Link, NavLink, ScrollRestoration, useScrollRestoration as UNSAFE_useScrollRestoration, createBrowserRouter, createHashRouter, createSearchParams, HistoryRouter as unstable_HistoryRouter, usePrompt as unstable_usePrompt, useBeforeUnload, useFetcher, useFetchers, useFormAction, useLinkClickHandler, useSearchParams, useSubmit };
|
|
1046
1029
|
//# sourceMappingURL=index.js.map
|