react-router 6.0.0-beta.8 → 6.1.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/index.d.ts +57 -35
- package/index.js +72 -48
- package/index.js.map +1 -1
- package/main.js +1 -1
- package/package.json +4 -2
- package/react-router.development.js +72 -48
- package/react-router.development.js.map +1 -1
- package/react-router.production.min.js +2 -2
- package/react-router.production.min.js.map +1 -1
- package/umd/react-router.development.js +73 -47
- package/umd/react-router.development.js.map +1 -1
- package/umd/react-router.production.min.js +2 -2
- package/umd/react-router.production.min.js.map +1 -1
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import type { History, InitialEntry, Location, Path, To } from "history";
|
|
3
|
+
import { Action as NavigationType } from "history";
|
|
4
|
+
export type { Location, Path, To, NavigationType };
|
|
4
5
|
/**
|
|
5
6
|
* A Navigator is a "location changer"; it's how you get to different locations.
|
|
6
7
|
*
|
|
@@ -10,7 +11,7 @@ import type { History, InitialEntry, Location, Path, State, To } from "history";
|
|
|
10
11
|
* to avoid "tearing" that may occur in a suspense-enabled app if the action
|
|
11
12
|
* and/or location were to be read directly from the history instance.
|
|
12
13
|
*/
|
|
13
|
-
export declare type Navigator =
|
|
14
|
+
export declare type Navigator = Pick<History, "go" | "push" | "replace" | "createHref">;
|
|
14
15
|
interface NavigationContextObject {
|
|
15
16
|
basename: string;
|
|
16
17
|
navigator: Navigator;
|
|
@@ -18,8 +19,8 @@ interface NavigationContextObject {
|
|
|
18
19
|
}
|
|
19
20
|
declare const NavigationContext: React.Context<NavigationContextObject>;
|
|
20
21
|
interface LocationContextObject {
|
|
21
|
-
action: Action;
|
|
22
22
|
location: Location;
|
|
23
|
+
navigationType: NavigationType;
|
|
23
24
|
}
|
|
24
25
|
declare const LocationContext: React.Context<LocationContextObject>;
|
|
25
26
|
interface RouteContextObject {
|
|
@@ -36,13 +37,13 @@ export interface MemoryRouterProps {
|
|
|
36
37
|
/**
|
|
37
38
|
* A <Router> that stores all entries in memory.
|
|
38
39
|
*
|
|
39
|
-
* @see https://reactrouter.com/api
|
|
40
|
+
* @see https://reactrouter.com/docs/en/v6/api#memoryrouter
|
|
40
41
|
*/
|
|
41
42
|
export declare function MemoryRouter({ basename, children, initialEntries, initialIndex }: MemoryRouterProps): React.ReactElement;
|
|
42
43
|
export interface NavigateProps {
|
|
43
44
|
to: To;
|
|
44
45
|
replace?: boolean;
|
|
45
|
-
state?:
|
|
46
|
+
state?: any;
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
49
|
* Changes the current location.
|
|
@@ -51,17 +52,18 @@ export interface NavigateProps {
|
|
|
51
52
|
* able to use hooks. In functional components, we recommend you use the
|
|
52
53
|
* `useNavigate` hook instead.
|
|
53
54
|
*
|
|
54
|
-
* @see https://reactrouter.com/api
|
|
55
|
+
* @see https://reactrouter.com/docs/en/v6/api#navigate
|
|
55
56
|
*/
|
|
56
57
|
export declare function Navigate({ to, replace, state }: NavigateProps): null;
|
|
57
58
|
export interface OutletProps {
|
|
59
|
+
context?: unknown;
|
|
58
60
|
}
|
|
59
61
|
/**
|
|
60
62
|
* Renders the child route's element, if there is one.
|
|
61
63
|
*
|
|
62
|
-
* @see https://reactrouter.com/api
|
|
64
|
+
* @see https://reactrouter.com/docs/en/v6/api#outlet
|
|
63
65
|
*/
|
|
64
|
-
export declare function Outlet(
|
|
66
|
+
export declare function Outlet(props: OutletProps): React.ReactElement | null;
|
|
65
67
|
export interface RouteProps {
|
|
66
68
|
caseSensitive?: boolean;
|
|
67
69
|
children?: React.ReactNode;
|
|
@@ -87,14 +89,14 @@ export interface IndexRouteProps {
|
|
|
87
89
|
/**
|
|
88
90
|
* Declares an element that should be rendered at a certain URL path.
|
|
89
91
|
*
|
|
90
|
-
* @see https://reactrouter.com/api
|
|
92
|
+
* @see https://reactrouter.com/docs/en/v6/api#route
|
|
91
93
|
*/
|
|
92
94
|
export declare function Route(_props: PathRouteProps | LayoutRouteProps | IndexRouteProps): React.ReactElement | null;
|
|
93
95
|
export interface RouterProps {
|
|
94
|
-
action?: Action;
|
|
95
96
|
basename?: string;
|
|
96
97
|
children?: React.ReactNode;
|
|
97
98
|
location: Partial<Location> | string;
|
|
99
|
+
navigationType?: NavigationType;
|
|
98
100
|
navigator: Navigator;
|
|
99
101
|
static?: boolean;
|
|
100
102
|
}
|
|
@@ -105,9 +107,9 @@ export interface RouterProps {
|
|
|
105
107
|
* router that is more specific to your environment such as a <BrowserRouter>
|
|
106
108
|
* in web browsers or a <StaticRouter> for server rendering.
|
|
107
109
|
*
|
|
108
|
-
* @see https://reactrouter.com/api
|
|
110
|
+
* @see https://reactrouter.com/docs/en/v6/api#router
|
|
109
111
|
*/
|
|
110
|
-
export declare function Router({
|
|
112
|
+
export declare function Router({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp }: RouterProps): React.ReactElement | null;
|
|
111
113
|
export interface RoutesProps {
|
|
112
114
|
children?: React.ReactNode;
|
|
113
115
|
location?: Partial<Location> | string;
|
|
@@ -116,20 +118,20 @@ export interface RoutesProps {
|
|
|
116
118
|
* A container for a nested tree of <Route> elements that renders the branch
|
|
117
119
|
* that best matches the current location.
|
|
118
120
|
*
|
|
119
|
-
* @see https://reactrouter.com/api
|
|
121
|
+
* @see https://reactrouter.com/docs/en/v6/api#routes
|
|
120
122
|
*/
|
|
121
123
|
export declare function Routes({ children, location }: RoutesProps): React.ReactElement | null;
|
|
122
124
|
/**
|
|
123
125
|
* Returns the full href for the given "to" value. This is useful for building
|
|
124
126
|
* custom links that are also accessible and preserve right-click behavior.
|
|
125
127
|
*
|
|
126
|
-
* @see https://reactrouter.com/api
|
|
128
|
+
* @see https://reactrouter.com/docs/en/v6/api#usehref
|
|
127
129
|
*/
|
|
128
130
|
export declare function useHref(to: To): string;
|
|
129
131
|
/**
|
|
130
132
|
* Returns true if this component is a descendant of a <Router>.
|
|
131
133
|
*
|
|
132
|
-
* @see https://reactrouter.com/api
|
|
134
|
+
* @see https://reactrouter.com/docs/en/v6/api#useinroutercontext
|
|
133
135
|
*/
|
|
134
136
|
export declare function useInRouterContext(): boolean;
|
|
135
137
|
/**
|
|
@@ -140,17 +142,29 @@ export declare function useInRouterContext(): boolean;
|
|
|
140
142
|
* "routing" in your app, and we'd like to know what your use case is. We may
|
|
141
143
|
* be able to provide something higher-level to better suit your needs.
|
|
142
144
|
*
|
|
143
|
-
* @see https://reactrouter.com/api
|
|
145
|
+
* @see https://reactrouter.com/docs/en/v6/api#uselocation
|
|
144
146
|
*/
|
|
145
147
|
export declare function useLocation(): Location;
|
|
148
|
+
declare type ParamParseFailed = {
|
|
149
|
+
failed: true;
|
|
150
|
+
};
|
|
151
|
+
declare type ParamParseSegment<Segment extends string> = Segment extends `${infer LeftSegment}/${infer RightSegment}` ? ParamParseSegment<LeftSegment> extends infer LeftResult ? ParamParseSegment<RightSegment> extends infer RightResult ? LeftResult extends string ? RightResult extends string ? LeftResult | RightResult : LeftResult : RightResult extends string ? RightResult : ParamParseFailed : ParamParseFailed : ParamParseSegment<RightSegment> extends infer RightResult ? RightResult extends string ? RightResult : ParamParseFailed : ParamParseFailed : Segment extends `:${infer Remaining}` ? Remaining : ParamParseFailed;
|
|
152
|
+
declare type ParamParseKey<Segment extends string> = ParamParseSegment<Segment> extends string ? ParamParseSegment<Segment> : string;
|
|
153
|
+
/**
|
|
154
|
+
* Returns the current navigation action which describes how the router came to
|
|
155
|
+
* the current location, either by a pop, push, or replace on the history stack.
|
|
156
|
+
*
|
|
157
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigationtype
|
|
158
|
+
*/
|
|
159
|
+
export declare function useNavigationType(): NavigationType;
|
|
146
160
|
/**
|
|
147
161
|
* Returns true if the URL for the given "to" value matches the current URL.
|
|
148
162
|
* This is useful for components that need to know "active" state, e.g.
|
|
149
163
|
* <NavLink>.
|
|
150
164
|
*
|
|
151
|
-
* @see https://reactrouter.com/api
|
|
165
|
+
* @see https://reactrouter.com/docs/en/v6/api#usematch
|
|
152
166
|
*/
|
|
153
|
-
export declare function useMatch<ParamKey extends
|
|
167
|
+
export declare function useMatch<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path): PathMatch<ParamKey> | null;
|
|
154
168
|
/**
|
|
155
169
|
* The interface for the navigate() function returned from useNavigate().
|
|
156
170
|
*/
|
|
@@ -160,33 +174,41 @@ export interface NavigateFunction {
|
|
|
160
174
|
}
|
|
161
175
|
export interface NavigateOptions {
|
|
162
176
|
replace?: boolean;
|
|
163
|
-
state?:
|
|
177
|
+
state?: any;
|
|
164
178
|
}
|
|
165
179
|
/**
|
|
166
180
|
* Returns an imperative method for changing the location. Used by <Link>s, but
|
|
167
181
|
* may also be used by other elements to change the location.
|
|
168
182
|
*
|
|
169
|
-
* @see https://reactrouter.com/api
|
|
183
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigate
|
|
170
184
|
*/
|
|
171
185
|
export declare function useNavigate(): NavigateFunction;
|
|
186
|
+
/**
|
|
187
|
+
* Returns the context (if provided) for the child route at this level of the route
|
|
188
|
+
* hierarchy.
|
|
189
|
+
* @see https://reactrouter.com/docs/en/v6/api#useoutletcontext
|
|
190
|
+
*/
|
|
191
|
+
export declare function useOutletContext<Context = unknown>(): Context;
|
|
172
192
|
/**
|
|
173
193
|
* Returns the element for the child route at this level of the route
|
|
174
194
|
* hierarchy. Used internally by <Outlet> to render child routes.
|
|
175
195
|
*
|
|
176
|
-
* @see https://reactrouter.com/api
|
|
196
|
+
* @see https://reactrouter.com/docs/en/v6/api#useoutlet
|
|
177
197
|
*/
|
|
178
|
-
export declare function useOutlet(): React.ReactElement | null;
|
|
198
|
+
export declare function useOutlet(context?: unknown): React.ReactElement | null;
|
|
179
199
|
/**
|
|
180
200
|
* Returns an object of key/value pairs of the dynamic params from the current
|
|
181
201
|
* URL that were matched by the route path.
|
|
182
202
|
*
|
|
183
|
-
* @see https://reactrouter.com/api
|
|
203
|
+
* @see https://reactrouter.com/docs/en/v6/api#useparams
|
|
184
204
|
*/
|
|
185
|
-
export declare function useParams<
|
|
205
|
+
export declare function useParams<ParamsOrKey extends string | Record<string, string | undefined> = string>(): Readonly<[
|
|
206
|
+
ParamsOrKey
|
|
207
|
+
] extends [string] ? Params<ParamsOrKey> : Partial<ParamsOrKey>>;
|
|
186
208
|
/**
|
|
187
209
|
* Resolves the pathname of the given `to` value against the current location.
|
|
188
210
|
*
|
|
189
|
-
* @see https://reactrouter.com/api
|
|
211
|
+
* @see https://reactrouter.com/docs/en/v6/api#useresolvedpath
|
|
190
212
|
*/
|
|
191
213
|
export declare function useResolvedPath(to: To): Path;
|
|
192
214
|
/**
|
|
@@ -195,7 +217,7 @@ export declare function useResolvedPath(to: To): Path;
|
|
|
195
217
|
* elements in the tree must render an <Outlet> to render their child route's
|
|
196
218
|
* element.
|
|
197
219
|
*
|
|
198
|
-
* @see https://reactrouter.com/api
|
|
220
|
+
* @see https://reactrouter.com/docs/en/v6/api#useroutes
|
|
199
221
|
*/
|
|
200
222
|
export declare function useRoutes(routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null;
|
|
201
223
|
/**
|
|
@@ -203,7 +225,7 @@ export declare function useRoutes(routes: RouteObject[], locationArg?: Partial<L
|
|
|
203
225
|
* either a `<Route>` element or an array of them. Used internally by
|
|
204
226
|
* `<Routes>` to create a route config from its children.
|
|
205
227
|
*
|
|
206
|
-
* @see https://reactrouter.com/api
|
|
228
|
+
* @see https://reactrouter.com/docs/en/v6/api#createroutesfromchildren
|
|
207
229
|
*/
|
|
208
230
|
export declare function createRoutesFromChildren(children: React.ReactNode): RouteObject[];
|
|
209
231
|
/**
|
|
@@ -226,7 +248,7 @@ export interface RouteObject {
|
|
|
226
248
|
/**
|
|
227
249
|
* Returns a path with params interpolated.
|
|
228
250
|
*
|
|
229
|
-
* @see https://reactrouter.com/api
|
|
251
|
+
* @see https://reactrouter.com/docs/en/v6/api#generatepath
|
|
230
252
|
*/
|
|
231
253
|
export declare function generatePath(path: string, params?: Params): string;
|
|
232
254
|
/**
|
|
@@ -253,7 +275,7 @@ export interface RouteMatch<ParamKey extends string = string> {
|
|
|
253
275
|
/**
|
|
254
276
|
* Matches the given routes to a location and returns the match data.
|
|
255
277
|
*
|
|
256
|
-
* @see https://reactrouter.com/api
|
|
278
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchroutes
|
|
257
279
|
*/
|
|
258
280
|
export declare function matchRoutes(routes: RouteObject[], locationArg: Partial<Location> | string, basename?: string): RouteMatch[] | null;
|
|
259
281
|
/**
|
|
@@ -263,13 +285,13 @@ export declare function renderMatches(matches: RouteMatch[] | null): React.React
|
|
|
263
285
|
/**
|
|
264
286
|
* A PathPattern is used to match on some portion of a URL pathname.
|
|
265
287
|
*/
|
|
266
|
-
export interface PathPattern {
|
|
288
|
+
export interface PathPattern<Path extends string = string> {
|
|
267
289
|
/**
|
|
268
290
|
* A string to match against a URL pathname. May contain `:id`-style segments
|
|
269
291
|
* to indicate placeholders for dynamic parameters. May also end with `/*` to
|
|
270
292
|
* indicate matching the rest of the URL pathname.
|
|
271
293
|
*/
|
|
272
|
-
path:
|
|
294
|
+
path: Path;
|
|
273
295
|
/**
|
|
274
296
|
* Should be `true` if the static portions of the `path` should be matched in
|
|
275
297
|
* the same case.
|
|
@@ -305,13 +327,13 @@ export interface PathMatch<ParamKey extends string = string> {
|
|
|
305
327
|
* Performs pattern matching on a URL pathname and returns information about
|
|
306
328
|
* the match.
|
|
307
329
|
*
|
|
308
|
-
* @see https://reactrouter.com/api
|
|
330
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchpath
|
|
309
331
|
*/
|
|
310
|
-
export declare function matchPath<ParamKey extends
|
|
332
|
+
export declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
|
|
311
333
|
/**
|
|
312
334
|
* Returns a resolved path object relative to the given pathname.
|
|
313
335
|
*
|
|
314
|
-
* @see https://reactrouter.com/api
|
|
336
|
+
* @see https://reactrouter.com/docs/en/v6/api#resolvepath
|
|
315
337
|
*/
|
|
316
338
|
export declare function resolvePath(to: To, fromPathname?: string): Path;
|
|
317
339
|
/** @internal */
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v6.
|
|
2
|
+
* React Router v6.1.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -80,7 +80,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
80
80
|
/**
|
|
81
81
|
* A <Router> that stores all entries in memory.
|
|
82
82
|
*
|
|
83
|
-
* @see https://reactrouter.com/api
|
|
83
|
+
* @see https://reactrouter.com/docs/en/v6/api#memoryrouter
|
|
84
84
|
*/
|
|
85
85
|
function MemoryRouter(_ref) {
|
|
86
86
|
let {
|
|
@@ -107,8 +107,8 @@ function MemoryRouter(_ref) {
|
|
|
107
107
|
return /*#__PURE__*/createElement(Router, {
|
|
108
108
|
basename: basename,
|
|
109
109
|
children: children,
|
|
110
|
-
action: state.action,
|
|
111
110
|
location: state.location,
|
|
111
|
+
navigationType: state.action,
|
|
112
112
|
navigator: history
|
|
113
113
|
});
|
|
114
114
|
}
|
|
@@ -120,7 +120,7 @@ function MemoryRouter(_ref) {
|
|
|
120
120
|
* able to use hooks. In functional components, we recommend you use the
|
|
121
121
|
* `useNavigate` hook instead.
|
|
122
122
|
*
|
|
123
|
-
* @see https://reactrouter.com/api
|
|
123
|
+
* @see https://reactrouter.com/docs/en/v6/api#navigate
|
|
124
124
|
*/
|
|
125
125
|
function Navigate(_ref2) {
|
|
126
126
|
let {
|
|
@@ -145,16 +145,16 @@ function Navigate(_ref2) {
|
|
|
145
145
|
/**
|
|
146
146
|
* Renders the child route's element, if there is one.
|
|
147
147
|
*
|
|
148
|
-
* @see https://reactrouter.com/api
|
|
148
|
+
* @see https://reactrouter.com/docs/en/v6/api#outlet
|
|
149
149
|
*/
|
|
150
|
-
function Outlet(
|
|
151
|
-
return useOutlet();
|
|
150
|
+
function Outlet(props) {
|
|
151
|
+
return useOutlet(props.context);
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/**
|
|
155
155
|
* Declares an element that should be rendered at a certain URL path.
|
|
156
156
|
*
|
|
157
|
-
* @see https://reactrouter.com/api
|
|
157
|
+
* @see https://reactrouter.com/docs/en/v6/api#route
|
|
158
158
|
*/
|
|
159
159
|
function Route(_props) {
|
|
160
160
|
process.env.NODE_ENV !== "production" ? 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>.") : invariant(false) ;
|
|
@@ -167,14 +167,14 @@ function Route(_props) {
|
|
|
167
167
|
* router that is more specific to your environment such as a <BrowserRouter>
|
|
168
168
|
* in web browsers or a <StaticRouter> for server rendering.
|
|
169
169
|
*
|
|
170
|
-
* @see https://reactrouter.com/api
|
|
170
|
+
* @see https://reactrouter.com/docs/en/v6/api#router
|
|
171
171
|
*/
|
|
172
172
|
function Router(_ref3) {
|
|
173
173
|
let {
|
|
174
|
-
action = Action.Pop,
|
|
175
174
|
basename: basenameProp = "/",
|
|
176
175
|
children = null,
|
|
177
176
|
location: locationProp,
|
|
177
|
+
navigationType = Action.Pop,
|
|
178
178
|
navigator,
|
|
179
179
|
static: staticProp = false
|
|
180
180
|
} = _ref3;
|
|
@@ -223,8 +223,8 @@ function Router(_ref3) {
|
|
|
223
223
|
}, /*#__PURE__*/createElement(LocationContext.Provider, {
|
|
224
224
|
children: children,
|
|
225
225
|
value: {
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
location,
|
|
227
|
+
navigationType
|
|
228
228
|
}
|
|
229
229
|
}));
|
|
230
230
|
}
|
|
@@ -233,7 +233,7 @@ function Router(_ref3) {
|
|
|
233
233
|
* A container for a nested tree of <Route> elements that renders the branch
|
|
234
234
|
* that best matches the current location.
|
|
235
235
|
*
|
|
236
|
-
* @see https://reactrouter.com/api
|
|
236
|
+
* @see https://reactrouter.com/docs/en/v6/api#routes
|
|
237
237
|
*/
|
|
238
238
|
function Routes(_ref4) {
|
|
239
239
|
let {
|
|
@@ -249,7 +249,7 @@ function Routes(_ref4) {
|
|
|
249
249
|
* Returns the full href for the given "to" value. This is useful for building
|
|
250
250
|
* custom links that are also accessible and preserve right-click behavior.
|
|
251
251
|
*
|
|
252
|
-
* @see https://reactrouter.com/api
|
|
252
|
+
* @see https://reactrouter.com/docs/en/v6/api#usehref
|
|
253
253
|
*/
|
|
254
254
|
|
|
255
255
|
function useHref(to) {
|
|
@@ -274,15 +274,15 @@ function useHref(to) {
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
return navigator.createHref({
|
|
277
|
-
hash,
|
|
278
277
|
pathname: joinedPathname,
|
|
279
|
-
search
|
|
278
|
+
search,
|
|
279
|
+
hash
|
|
280
280
|
});
|
|
281
281
|
}
|
|
282
282
|
/**
|
|
283
283
|
* Returns true if this component is a descendant of a <Router>.
|
|
284
284
|
*
|
|
285
|
-
* @see https://reactrouter.com/api
|
|
285
|
+
* @see https://reactrouter.com/docs/en/v6/api#useinroutercontext
|
|
286
286
|
*/
|
|
287
287
|
|
|
288
288
|
function useInRouterContext() {
|
|
@@ -296,7 +296,7 @@ function useInRouterContext() {
|
|
|
296
296
|
* "routing" in your app, and we'd like to know what your use case is. We may
|
|
297
297
|
* be able to provide something higher-level to better suit your needs.
|
|
298
298
|
*
|
|
299
|
-
* @see https://reactrouter.com/api
|
|
299
|
+
* @see https://reactrouter.com/docs/en/v6/api#uselocation
|
|
300
300
|
*/
|
|
301
301
|
|
|
302
302
|
function useLocation() {
|
|
@@ -305,19 +305,32 @@ function useLocation() {
|
|
|
305
305
|
"useLocation() may be used only in the context of a <Router> component.") : invariant(false) : void 0;
|
|
306
306
|
return useContext(LocationContext).location;
|
|
307
307
|
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Returns the current navigation action which describes how the router came to
|
|
311
|
+
* the current location, either by a pop, push, or replace on the history stack.
|
|
312
|
+
*
|
|
313
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigationtype
|
|
314
|
+
*/
|
|
315
|
+
function useNavigationType() {
|
|
316
|
+
return useContext(LocationContext).navigationType;
|
|
317
|
+
}
|
|
308
318
|
/**
|
|
309
319
|
* Returns true if the URL for the given "to" value matches the current URL.
|
|
310
320
|
* This is useful for components that need to know "active" state, e.g.
|
|
311
321
|
* <NavLink>.
|
|
312
322
|
*
|
|
313
|
-
* @see https://reactrouter.com/api
|
|
323
|
+
* @see https://reactrouter.com/docs/en/v6/api#usematch
|
|
314
324
|
*/
|
|
315
325
|
|
|
316
326
|
function useMatch(pattern) {
|
|
317
327
|
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
318
328
|
// router loaded. We can help them understand how to avoid that.
|
|
319
329
|
"useMatch() may be used only in the context of a <Router> component.") : invariant(false) : void 0;
|
|
320
|
-
|
|
330
|
+
let {
|
|
331
|
+
pathname
|
|
332
|
+
} = useLocation();
|
|
333
|
+
return useMemo(() => matchPath(pattern, pathname), [pathname, pattern]);
|
|
321
334
|
}
|
|
322
335
|
/**
|
|
323
336
|
* The interface for the navigate() function returned from useNavigate().
|
|
@@ -327,7 +340,7 @@ function useMatch(pattern) {
|
|
|
327
340
|
* Returns an imperative method for changing the location. Used by <Link>s, but
|
|
328
341
|
* may also be used by other elements to change the location.
|
|
329
342
|
*
|
|
330
|
-
* @see https://reactrouter.com/api
|
|
343
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigate
|
|
331
344
|
*/
|
|
332
345
|
function useNavigate() {
|
|
333
346
|
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
@@ -371,21 +384,34 @@ function useNavigate() {
|
|
|
371
384
|
}, [basename, navigator, routePathnamesJson, locationPathname]);
|
|
372
385
|
return navigate;
|
|
373
386
|
}
|
|
387
|
+
const OutletContext = /*#__PURE__*/createContext(null);
|
|
388
|
+
/**
|
|
389
|
+
* Returns the context (if provided) for the child route at this level of the route
|
|
390
|
+
* hierarchy.
|
|
391
|
+
* @see https://reactrouter.com/docs/en/v6/api#useoutletcontext
|
|
392
|
+
*/
|
|
393
|
+
|
|
394
|
+
function useOutletContext() {
|
|
395
|
+
return useContext(OutletContext);
|
|
396
|
+
}
|
|
374
397
|
/**
|
|
375
398
|
* Returns the element for the child route at this level of the route
|
|
376
399
|
* hierarchy. Used internally by <Outlet> to render child routes.
|
|
377
400
|
*
|
|
378
|
-
* @see https://reactrouter.com/api
|
|
401
|
+
* @see https://reactrouter.com/docs/en/v6/api#useoutlet
|
|
379
402
|
*/
|
|
380
403
|
|
|
381
|
-
function useOutlet() {
|
|
382
|
-
|
|
404
|
+
function useOutlet(context) {
|
|
405
|
+
let outlet = useContext(RouteContext).outlet;
|
|
406
|
+
return /*#__PURE__*/createElement(OutletContext.Provider, {
|
|
407
|
+
value: context
|
|
408
|
+
}, outlet);
|
|
383
409
|
}
|
|
384
410
|
/**
|
|
385
411
|
* Returns an object of key/value pairs of the dynamic params from the current
|
|
386
412
|
* URL that were matched by the route path.
|
|
387
413
|
*
|
|
388
|
-
* @see https://reactrouter.com/api
|
|
414
|
+
* @see https://reactrouter.com/docs/en/v6/api#useparams
|
|
389
415
|
*/
|
|
390
416
|
|
|
391
417
|
function useParams() {
|
|
@@ -398,7 +424,7 @@ function useParams() {
|
|
|
398
424
|
/**
|
|
399
425
|
* Resolves the pathname of the given `to` value against the current location.
|
|
400
426
|
*
|
|
401
|
-
* @see https://reactrouter.com/api
|
|
427
|
+
* @see https://reactrouter.com/docs/en/v6/api#useresolvedpath
|
|
402
428
|
*/
|
|
403
429
|
|
|
404
430
|
function useResolvedPath(to) {
|
|
@@ -417,7 +443,7 @@ function useResolvedPath(to) {
|
|
|
417
443
|
* elements in the tree must render an <Outlet> to render their child route's
|
|
418
444
|
* element.
|
|
419
445
|
*
|
|
420
|
-
* @see https://reactrouter.com/api
|
|
446
|
+
* @see https://reactrouter.com/docs/en/v6/api#useroutes
|
|
421
447
|
*/
|
|
422
448
|
|
|
423
449
|
function useRoutes(routes, locationArg) {
|
|
@@ -455,7 +481,7 @@ function useRoutes(routes, locationArg) {
|
|
|
455
481
|
// );
|
|
456
482
|
// }
|
|
457
483
|
let parentPath = parentRoute && parentRoute.path || "";
|
|
458
|
-
warningOnce(parentPathname, !parentRoute || parentPath.endsWith("*"), "You rendered descendant <Routes> (or called `useRoutes()`) at " + ("\"" + parentPathname + "\" (under <Route path=\"" + parentPath + "\">) but the ") + "parent route path has no trailing \"*\". This means if you navigate " + "deeper, the parent won't match anymore and therefore the child " + "routes will never render.\n\n" + ("Please change the parent <Route path=\"" + parentPath + "\"> to <Route ") + ("path=\"" + parentPath + "
|
|
484
|
+
warningOnce(parentPathname, !parentRoute || parentPath.endsWith("*"), "You rendered descendant <Routes> (or called `useRoutes()`) at " + ("\"" + parentPathname + "\" (under <Route path=\"" + parentPath + "\">) but the ") + "parent route path has no trailing \"*\". This means if you navigate " + "deeper, the parent won't match anymore and therefore the child " + "routes will never render.\n\n" + ("Please change the parent <Route path=\"" + parentPath + "\"> to <Route ") + ("path=\"" + (parentPath === "/" ? "*" : parentPath + "/*") + "\">."));
|
|
459
485
|
}
|
|
460
486
|
|
|
461
487
|
let locationFromContext = useLocation();
|
|
@@ -479,13 +505,13 @@ function useRoutes(routes, locationArg) {
|
|
|
479
505
|
|
|
480
506
|
if (process.env.NODE_ENV !== "production") {
|
|
481
507
|
process.env.NODE_ENV !== "production" ? warning(parentRoute || matches != null, "No routes matched location \"" + location.pathname + location.search + location.hash + "\" ") : void 0;
|
|
482
|
-
process.env.NODE_ENV !== "production" ? warning(matches == null || matches[matches.length - 1].route.element
|
|
508
|
+
process.env.NODE_ENV !== "production" ? warning(matches == null || matches[matches.length - 1].route.element !== undefined, "Matched leaf route at location \"" + location.pathname + location.search + location.hash + "\" does not have an element. " + "This means it will render an <Outlet /> with a null value by default resulting in an \"empty\" page.") : void 0;
|
|
483
509
|
}
|
|
484
510
|
|
|
485
511
|
return _renderMatches(matches && matches.map(match => Object.assign({}, match, {
|
|
486
512
|
params: Object.assign({}, parentParams, match.params),
|
|
487
513
|
pathname: joinPaths([parentPathnameBase, match.pathname]),
|
|
488
|
-
pathnameBase: joinPaths([parentPathnameBase, match.pathnameBase])
|
|
514
|
+
pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([parentPathnameBase, match.pathnameBase])
|
|
489
515
|
})), parentMatches);
|
|
490
516
|
} ///////////////////////////////////////////////////////////////////////////////
|
|
491
517
|
// UTILS
|
|
@@ -496,7 +522,7 @@ function useRoutes(routes, locationArg) {
|
|
|
496
522
|
* either a `<Route>` element or an array of them. Used internally by
|
|
497
523
|
* `<Routes>` to create a route config from its children.
|
|
498
524
|
*
|
|
499
|
-
* @see https://reactrouter.com/api
|
|
525
|
+
* @see https://reactrouter.com/docs/en/v6/api#createroutesfromchildren
|
|
500
526
|
*/
|
|
501
527
|
|
|
502
528
|
function createRoutesFromChildren(children) {
|
|
@@ -514,6 +540,7 @@ function createRoutesFromChildren(children) {
|
|
|
514
540
|
return;
|
|
515
541
|
}
|
|
516
542
|
|
|
543
|
+
!(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;
|
|
517
544
|
let route = {
|
|
518
545
|
caseSensitive: element.props.caseSensitive,
|
|
519
546
|
element: element.props.element,
|
|
@@ -536,7 +563,7 @@ function createRoutesFromChildren(children) {
|
|
|
536
563
|
/**
|
|
537
564
|
* Returns a path with params interpolated.
|
|
538
565
|
*
|
|
539
|
-
* @see https://reactrouter.com/api
|
|
566
|
+
* @see https://reactrouter.com/docs/en/v6/api#generatepath
|
|
540
567
|
*/
|
|
541
568
|
function generatePath(path, params) {
|
|
542
569
|
if (params === void 0) {
|
|
@@ -555,7 +582,7 @@ function generatePath(path, params) {
|
|
|
555
582
|
/**
|
|
556
583
|
* Matches the given routes to a location and returns the match data.
|
|
557
584
|
*
|
|
558
|
-
* @see https://reactrouter.com/api
|
|
585
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchroutes
|
|
559
586
|
*/
|
|
560
587
|
function matchRoutes(routes, locationArg, basename) {
|
|
561
588
|
if (basename === void 0) {
|
|
@@ -574,7 +601,7 @@ function matchRoutes(routes, locationArg, basename) {
|
|
|
574
601
|
let matches = null;
|
|
575
602
|
|
|
576
603
|
for (let i = 0; matches == null && i < branches.length; ++i) {
|
|
577
|
-
matches = matchRouteBranch(branches[i],
|
|
604
|
+
matches = matchRouteBranch(branches[i], pathname);
|
|
578
605
|
}
|
|
579
606
|
|
|
580
607
|
return matches;
|
|
@@ -597,7 +624,8 @@ function flattenRoutes(routes, branches, parentsMeta, parentPath) {
|
|
|
597
624
|
let meta = {
|
|
598
625
|
relativePath: route.path || "",
|
|
599
626
|
caseSensitive: route.caseSensitive === true,
|
|
600
|
-
childrenIndex: index
|
|
627
|
+
childrenIndex: index,
|
|
628
|
+
route
|
|
601
629
|
};
|
|
602
630
|
|
|
603
631
|
if (meta.relativePath.startsWith("/")) {
|
|
@@ -670,9 +698,7 @@ function compareIndexes(a, b) {
|
|
|
670
698
|
0;
|
|
671
699
|
}
|
|
672
700
|
|
|
673
|
-
function matchRouteBranch(branch,
|
|
674
|
-
routesArg, pathname) {
|
|
675
|
-
let routes = routesArg;
|
|
701
|
+
function matchRouteBranch(branch, pathname) {
|
|
676
702
|
let {
|
|
677
703
|
routesMeta
|
|
678
704
|
} = branch;
|
|
@@ -691,7 +717,7 @@ routesArg, pathname) {
|
|
|
691
717
|
}, remainingPathname);
|
|
692
718
|
if (!match) return null;
|
|
693
719
|
Object.assign(matchedParams, match.params);
|
|
694
|
-
let route =
|
|
720
|
+
let route = meta.route;
|
|
695
721
|
matches.push({
|
|
696
722
|
params: matchedParams,
|
|
697
723
|
pathname: joinPaths([matchedPathname, match.pathname]),
|
|
@@ -702,8 +728,6 @@ routesArg, pathname) {
|
|
|
702
728
|
if (match.pathnameBase !== "/") {
|
|
703
729
|
matchedPathname = joinPaths([matchedPathname, match.pathnameBase]);
|
|
704
730
|
}
|
|
705
|
-
|
|
706
|
-
routes = route.children;
|
|
707
731
|
}
|
|
708
732
|
|
|
709
733
|
return matches;
|
|
@@ -725,7 +749,7 @@ function _renderMatches(matches, parentMatches) {
|
|
|
725
749
|
if (matches == null) return null;
|
|
726
750
|
return matches.reduceRight((outlet, match, index) => {
|
|
727
751
|
return /*#__PURE__*/createElement(RouteContext.Provider, {
|
|
728
|
-
children: match.route.element
|
|
752
|
+
children: match.route.element !== undefined ? match.route.element : /*#__PURE__*/createElement(Outlet, null),
|
|
729
753
|
value: {
|
|
730
754
|
outlet,
|
|
731
755
|
matches: parentMatches.concat(matches.slice(0, index + 1))
|
|
@@ -742,7 +766,7 @@ function _renderMatches(matches, parentMatches) {
|
|
|
742
766
|
* Performs pattern matching on a URL pathname and returns information about
|
|
743
767
|
* the match.
|
|
744
768
|
*
|
|
745
|
-
* @see https://reactrouter.com/api
|
|
769
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchpath
|
|
746
770
|
*/
|
|
747
771
|
function matchPath(pattern, pathname) {
|
|
748
772
|
if (typeof pattern === "string") {
|
|
@@ -803,10 +827,10 @@ function compilePath(path, caseSensitive, end) {
|
|
|
803
827
|
: "(?:\\/(.+)|\\/*)$"; // Don't include the / in params["*"]
|
|
804
828
|
} else {
|
|
805
829
|
regexpSource += end ? "\\/*$" // When matching to the end, ignore trailing slashes
|
|
806
|
-
: // Otherwise,
|
|
807
|
-
// routes to matching only their own words and nothing more, e.g. parent
|
|
830
|
+
: // Otherwise, match a word boundary or a proceeding /. The word boundary restricts
|
|
831
|
+
// parent routes to matching only their own words and nothing more, e.g. parent
|
|
808
832
|
// route "/home" should not match "/home2".
|
|
809
|
-
"(?:\\b
|
|
833
|
+
"(?:\\b|\\/|$)";
|
|
810
834
|
}
|
|
811
835
|
|
|
812
836
|
let matcher = new RegExp(regexpSource, caseSensitive ? undefined : "i");
|
|
@@ -824,7 +848,7 @@ function safelyDecodeURIComponent(value, paramName) {
|
|
|
824
848
|
/**
|
|
825
849
|
* Returns a resolved path object relative to the given pathname.
|
|
826
850
|
*
|
|
827
|
-
* @see https://reactrouter.com/api
|
|
851
|
+
* @see https://reactrouter.com/docs/en/v6/api#resolvepath
|
|
828
852
|
*/
|
|
829
853
|
|
|
830
854
|
|
|
@@ -934,5 +958,5 @@ const normalizeSearch = search => !search || search === "?" ? "" : search.starts
|
|
|
934
958
|
|
|
935
959
|
const normalizeHash = hash => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash; ///////////////////////////////////////////////////////////////////////////////
|
|
936
960
|
|
|
937
|
-
export { MemoryRouter, Navigate, Outlet, Route, Router, Routes, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RouteContext as UNSAFE_RouteContext, createRoutesFromChildren, generatePath, matchPath, matchRoutes, renderMatches, resolvePath, useHref, useInRouterContext, useLocation, useMatch, useNavigate, useOutlet, useParams, useResolvedPath, useRoutes };
|
|
961
|
+
export { MemoryRouter, Navigate, Outlet, Route, Router, Routes, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RouteContext as UNSAFE_RouteContext, createRoutesFromChildren, generatePath, matchPath, matchRoutes, renderMatches, resolvePath, useHref, useInRouterContext, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes };
|
|
938
962
|
//# sourceMappingURL=index.js.map
|