react-router 6.0.0 → 6.1.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/index.d.ts +43 -29
- package/index.js +55 -41
- package/index.js.map +1 -1
- package/main.js +1 -1
- package/package.json +2 -2
- package/react-router.development.js +55 -41
- 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 +55 -40
- 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
|
@@ -11,7 +11,7 @@ export type { Location, Path, To, NavigationType };
|
|
|
11
11
|
* to avoid "tearing" that may occur in a suspense-enabled app if the action
|
|
12
12
|
* and/or location were to be read directly from the history instance.
|
|
13
13
|
*/
|
|
14
|
-
export declare type Navigator =
|
|
14
|
+
export declare type Navigator = Pick<History, "go" | "push" | "replace" | "createHref">;
|
|
15
15
|
interface NavigationContextObject {
|
|
16
16
|
basename: string;
|
|
17
17
|
navigator: Navigator;
|
|
@@ -37,7 +37,7 @@ export interface MemoryRouterProps {
|
|
|
37
37
|
/**
|
|
38
38
|
* A <Router> that stores all entries in memory.
|
|
39
39
|
*
|
|
40
|
-
* @see https://reactrouter.com/api
|
|
40
|
+
* @see https://reactrouter.com/docs/en/v6/api#memoryrouter
|
|
41
41
|
*/
|
|
42
42
|
export declare function MemoryRouter({ basename, children, initialEntries, initialIndex }: MemoryRouterProps): React.ReactElement;
|
|
43
43
|
export interface NavigateProps {
|
|
@@ -52,17 +52,18 @@ export interface NavigateProps {
|
|
|
52
52
|
* able to use hooks. In functional components, we recommend you use the
|
|
53
53
|
* `useNavigate` hook instead.
|
|
54
54
|
*
|
|
55
|
-
* @see https://reactrouter.com/api
|
|
55
|
+
* @see https://reactrouter.com/docs/en/v6/api#navigate
|
|
56
56
|
*/
|
|
57
57
|
export declare function Navigate({ to, replace, state }: NavigateProps): null;
|
|
58
58
|
export interface OutletProps {
|
|
59
|
+
context?: unknown;
|
|
59
60
|
}
|
|
60
61
|
/**
|
|
61
62
|
* Renders the child route's element, if there is one.
|
|
62
63
|
*
|
|
63
|
-
* @see https://reactrouter.com/api
|
|
64
|
+
* @see https://reactrouter.com/docs/en/v6/api#outlet
|
|
64
65
|
*/
|
|
65
|
-
export declare function Outlet(
|
|
66
|
+
export declare function Outlet(props: OutletProps): React.ReactElement | null;
|
|
66
67
|
export interface RouteProps {
|
|
67
68
|
caseSensitive?: boolean;
|
|
68
69
|
children?: React.ReactNode;
|
|
@@ -88,7 +89,7 @@ export interface IndexRouteProps {
|
|
|
88
89
|
/**
|
|
89
90
|
* Declares an element that should be rendered at a certain URL path.
|
|
90
91
|
*
|
|
91
|
-
* @see https://reactrouter.com/api
|
|
92
|
+
* @see https://reactrouter.com/docs/en/v6/api#route
|
|
92
93
|
*/
|
|
93
94
|
export declare function Route(_props: PathRouteProps | LayoutRouteProps | IndexRouteProps): React.ReactElement | null;
|
|
94
95
|
export interface RouterProps {
|
|
@@ -106,7 +107,7 @@ export interface RouterProps {
|
|
|
106
107
|
* router that is more specific to your environment such as a <BrowserRouter>
|
|
107
108
|
* in web browsers or a <StaticRouter> for server rendering.
|
|
108
109
|
*
|
|
109
|
-
* @see https://reactrouter.com/api
|
|
110
|
+
* @see https://reactrouter.com/docs/en/v6/api#router
|
|
110
111
|
*/
|
|
111
112
|
export declare function Router({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp }: RouterProps): React.ReactElement | null;
|
|
112
113
|
export interface RoutesProps {
|
|
@@ -117,20 +118,20 @@ export interface RoutesProps {
|
|
|
117
118
|
* A container for a nested tree of <Route> elements that renders the branch
|
|
118
119
|
* that best matches the current location.
|
|
119
120
|
*
|
|
120
|
-
* @see https://reactrouter.com/api
|
|
121
|
+
* @see https://reactrouter.com/docs/en/v6/api#routes
|
|
121
122
|
*/
|
|
122
123
|
export declare function Routes({ children, location }: RoutesProps): React.ReactElement | null;
|
|
123
124
|
/**
|
|
124
125
|
* Returns the full href for the given "to" value. This is useful for building
|
|
125
126
|
* custom links that are also accessible and preserve right-click behavior.
|
|
126
127
|
*
|
|
127
|
-
* @see https://reactrouter.com/api
|
|
128
|
+
* @see https://reactrouter.com/docs/en/v6/api#usehref
|
|
128
129
|
*/
|
|
129
130
|
export declare function useHref(to: To): string;
|
|
130
131
|
/**
|
|
131
132
|
* Returns true if this component is a descendant of a <Router>.
|
|
132
133
|
*
|
|
133
|
-
* @see https://reactrouter.com/api
|
|
134
|
+
* @see https://reactrouter.com/docs/en/v6/api#useinroutercontext
|
|
134
135
|
*/
|
|
135
136
|
export declare function useInRouterContext(): boolean;
|
|
136
137
|
/**
|
|
@@ -141,14 +142,19 @@ export declare function useInRouterContext(): boolean;
|
|
|
141
142
|
* "routing" in your app, and we'd like to know what your use case is. We may
|
|
142
143
|
* be able to provide something higher-level to better suit your needs.
|
|
143
144
|
*
|
|
144
|
-
* @see https://reactrouter.com/api
|
|
145
|
+
* @see https://reactrouter.com/docs/en/v6/api#uselocation
|
|
145
146
|
*/
|
|
146
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;
|
|
147
153
|
/**
|
|
148
154
|
* Returns the current navigation action which describes how the router came to
|
|
149
155
|
* the current location, either by a pop, push, or replace on the history stack.
|
|
150
156
|
*
|
|
151
|
-
* @see https://reactrouter.com/api
|
|
157
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigationtype
|
|
152
158
|
*/
|
|
153
159
|
export declare function useNavigationType(): NavigationType;
|
|
154
160
|
/**
|
|
@@ -156,9 +162,9 @@ export declare function useNavigationType(): NavigationType;
|
|
|
156
162
|
* This is useful for components that need to know "active" state, e.g.
|
|
157
163
|
* <NavLink>.
|
|
158
164
|
*
|
|
159
|
-
* @see https://reactrouter.com/api
|
|
165
|
+
* @see https://reactrouter.com/docs/en/v6/api#usematch
|
|
160
166
|
*/
|
|
161
|
-
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;
|
|
162
168
|
/**
|
|
163
169
|
* The interface for the navigate() function returned from useNavigate().
|
|
164
170
|
*/
|
|
@@ -174,27 +180,35 @@ export interface NavigateOptions {
|
|
|
174
180
|
* Returns an imperative method for changing the location. Used by <Link>s, but
|
|
175
181
|
* may also be used by other elements to change the location.
|
|
176
182
|
*
|
|
177
|
-
* @see https://reactrouter.com/api
|
|
183
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigate
|
|
178
184
|
*/
|
|
179
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;
|
|
180
192
|
/**
|
|
181
193
|
* Returns the element for the child route at this level of the route
|
|
182
194
|
* hierarchy. Used internally by <Outlet> to render child routes.
|
|
183
195
|
*
|
|
184
|
-
* @see https://reactrouter.com/api
|
|
196
|
+
* @see https://reactrouter.com/docs/en/v6/api#useoutlet
|
|
185
197
|
*/
|
|
186
|
-
export declare function useOutlet(): React.ReactElement | null;
|
|
198
|
+
export declare function useOutlet(context?: unknown): React.ReactElement | null;
|
|
187
199
|
/**
|
|
188
200
|
* Returns an object of key/value pairs of the dynamic params from the current
|
|
189
201
|
* URL that were matched by the route path.
|
|
190
202
|
*
|
|
191
|
-
* @see https://reactrouter.com/api
|
|
203
|
+
* @see https://reactrouter.com/docs/en/v6/api#useparams
|
|
192
204
|
*/
|
|
193
|
-
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>>;
|
|
194
208
|
/**
|
|
195
209
|
* Resolves the pathname of the given `to` value against the current location.
|
|
196
210
|
*
|
|
197
|
-
* @see https://reactrouter.com/api
|
|
211
|
+
* @see https://reactrouter.com/docs/en/v6/api#useresolvedpath
|
|
198
212
|
*/
|
|
199
213
|
export declare function useResolvedPath(to: To): Path;
|
|
200
214
|
/**
|
|
@@ -203,7 +217,7 @@ export declare function useResolvedPath(to: To): Path;
|
|
|
203
217
|
* elements in the tree must render an <Outlet> to render their child route's
|
|
204
218
|
* element.
|
|
205
219
|
*
|
|
206
|
-
* @see https://reactrouter.com/api
|
|
220
|
+
* @see https://reactrouter.com/docs/en/v6/api#useroutes
|
|
207
221
|
*/
|
|
208
222
|
export declare function useRoutes(routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null;
|
|
209
223
|
/**
|
|
@@ -211,7 +225,7 @@ export declare function useRoutes(routes: RouteObject[], locationArg?: Partial<L
|
|
|
211
225
|
* either a `<Route>` element or an array of them. Used internally by
|
|
212
226
|
* `<Routes>` to create a route config from its children.
|
|
213
227
|
*
|
|
214
|
-
* @see https://reactrouter.com/api
|
|
228
|
+
* @see https://reactrouter.com/docs/en/v6/api#createroutesfromchildren
|
|
215
229
|
*/
|
|
216
230
|
export declare function createRoutesFromChildren(children: React.ReactNode): RouteObject[];
|
|
217
231
|
/**
|
|
@@ -234,7 +248,7 @@ export interface RouteObject {
|
|
|
234
248
|
/**
|
|
235
249
|
* Returns a path with params interpolated.
|
|
236
250
|
*
|
|
237
|
-
* @see https://reactrouter.com/api
|
|
251
|
+
* @see https://reactrouter.com/docs/en/v6/api#generatepath
|
|
238
252
|
*/
|
|
239
253
|
export declare function generatePath(path: string, params?: Params): string;
|
|
240
254
|
/**
|
|
@@ -261,7 +275,7 @@ export interface RouteMatch<ParamKey extends string = string> {
|
|
|
261
275
|
/**
|
|
262
276
|
* Matches the given routes to a location and returns the match data.
|
|
263
277
|
*
|
|
264
|
-
* @see https://reactrouter.com/api
|
|
278
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchroutes
|
|
265
279
|
*/
|
|
266
280
|
export declare function matchRoutes(routes: RouteObject[], locationArg: Partial<Location> | string, basename?: string): RouteMatch[] | null;
|
|
267
281
|
/**
|
|
@@ -271,13 +285,13 @@ export declare function renderMatches(matches: RouteMatch[] | null): React.React
|
|
|
271
285
|
/**
|
|
272
286
|
* A PathPattern is used to match on some portion of a URL pathname.
|
|
273
287
|
*/
|
|
274
|
-
export interface PathPattern {
|
|
288
|
+
export interface PathPattern<Path extends string = string> {
|
|
275
289
|
/**
|
|
276
290
|
* A string to match against a URL pathname. May contain `:id`-style segments
|
|
277
291
|
* to indicate placeholders for dynamic parameters. May also end with `/*` to
|
|
278
292
|
* indicate matching the rest of the URL pathname.
|
|
279
293
|
*/
|
|
280
|
-
path:
|
|
294
|
+
path: Path;
|
|
281
295
|
/**
|
|
282
296
|
* Should be `true` if the static portions of the `path` should be matched in
|
|
283
297
|
* the same case.
|
|
@@ -313,13 +327,13 @@ export interface PathMatch<ParamKey extends string = string> {
|
|
|
313
327
|
* Performs pattern matching on a URL pathname and returns information about
|
|
314
328
|
* the match.
|
|
315
329
|
*
|
|
316
|
-
* @see https://reactrouter.com/api
|
|
330
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchpath
|
|
317
331
|
*/
|
|
318
|
-
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;
|
|
319
333
|
/**
|
|
320
334
|
* Returns a resolved path object relative to the given pathname.
|
|
321
335
|
*
|
|
322
|
-
* @see https://reactrouter.com/api
|
|
336
|
+
* @see https://reactrouter.com/docs/en/v6/api#resolvepath
|
|
323
337
|
*/
|
|
324
338
|
export declare function resolvePath(to: To, fromPathname?: string): Path;
|
|
325
339
|
/** @internal */
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v6.
|
|
2
|
+
* React Router v6.1.1
|
|
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 {
|
|
@@ -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,7 +167,7 @@ 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 {
|
|
@@ -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) {
|
|
@@ -282,7 +282,7 @@ function useHref(to) {
|
|
|
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,13 +305,13 @@ 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
|
+
|
|
308
309
|
/**
|
|
309
310
|
* Returns the current navigation action which describes how the router came to
|
|
310
311
|
* the current location, either by a pop, push, or replace on the history stack.
|
|
311
312
|
*
|
|
312
|
-
* @see https://reactrouter.com/api
|
|
313
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigationtype
|
|
313
314
|
*/
|
|
314
|
-
|
|
315
315
|
function useNavigationType() {
|
|
316
316
|
return useContext(LocationContext).navigationType;
|
|
317
317
|
}
|
|
@@ -320,14 +320,17 @@ function useNavigationType() {
|
|
|
320
320
|
* This is useful for components that need to know "active" state, e.g.
|
|
321
321
|
* <NavLink>.
|
|
322
322
|
*
|
|
323
|
-
* @see https://reactrouter.com/api
|
|
323
|
+
* @see https://reactrouter.com/docs/en/v6/api#usematch
|
|
324
324
|
*/
|
|
325
325
|
|
|
326
326
|
function useMatch(pattern) {
|
|
327
327
|
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
328
328
|
// router loaded. We can help them understand how to avoid that.
|
|
329
329
|
"useMatch() may be used only in the context of a <Router> component.") : invariant(false) : void 0;
|
|
330
|
-
|
|
330
|
+
let {
|
|
331
|
+
pathname
|
|
332
|
+
} = useLocation();
|
|
333
|
+
return useMemo(() => matchPath(pattern, pathname), [pathname, pattern]);
|
|
331
334
|
}
|
|
332
335
|
/**
|
|
333
336
|
* The interface for the navigate() function returned from useNavigate().
|
|
@@ -337,7 +340,7 @@ function useMatch(pattern) {
|
|
|
337
340
|
* Returns an imperative method for changing the location. Used by <Link>s, but
|
|
338
341
|
* may also be used by other elements to change the location.
|
|
339
342
|
*
|
|
340
|
-
* @see https://reactrouter.com/api
|
|
343
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigate
|
|
341
344
|
*/
|
|
342
345
|
function useNavigate() {
|
|
343
346
|
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
@@ -381,21 +384,34 @@ function useNavigate() {
|
|
|
381
384
|
}, [basename, navigator, routePathnamesJson, locationPathname]);
|
|
382
385
|
return navigate;
|
|
383
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
|
+
}
|
|
384
397
|
/**
|
|
385
398
|
* Returns the element for the child route at this level of the route
|
|
386
399
|
* hierarchy. Used internally by <Outlet> to render child routes.
|
|
387
400
|
*
|
|
388
|
-
* @see https://reactrouter.com/api
|
|
401
|
+
* @see https://reactrouter.com/docs/en/v6/api#useoutlet
|
|
389
402
|
*/
|
|
390
403
|
|
|
391
|
-
function useOutlet() {
|
|
392
|
-
|
|
404
|
+
function useOutlet(context) {
|
|
405
|
+
let outlet = useContext(RouteContext).outlet;
|
|
406
|
+
return /*#__PURE__*/createElement(OutletContext.Provider, {
|
|
407
|
+
value: context
|
|
408
|
+
}, outlet);
|
|
393
409
|
}
|
|
394
410
|
/**
|
|
395
411
|
* Returns an object of key/value pairs of the dynamic params from the current
|
|
396
412
|
* URL that were matched by the route path.
|
|
397
413
|
*
|
|
398
|
-
* @see https://reactrouter.com/api
|
|
414
|
+
* @see https://reactrouter.com/docs/en/v6/api#useparams
|
|
399
415
|
*/
|
|
400
416
|
|
|
401
417
|
function useParams() {
|
|
@@ -408,7 +424,7 @@ function useParams() {
|
|
|
408
424
|
/**
|
|
409
425
|
* Resolves the pathname of the given `to` value against the current location.
|
|
410
426
|
*
|
|
411
|
-
* @see https://reactrouter.com/api
|
|
427
|
+
* @see https://reactrouter.com/docs/en/v6/api#useresolvedpath
|
|
412
428
|
*/
|
|
413
429
|
|
|
414
430
|
function useResolvedPath(to) {
|
|
@@ -427,7 +443,7 @@ function useResolvedPath(to) {
|
|
|
427
443
|
* elements in the tree must render an <Outlet> to render their child route's
|
|
428
444
|
* element.
|
|
429
445
|
*
|
|
430
|
-
* @see https://reactrouter.com/api
|
|
446
|
+
* @see https://reactrouter.com/docs/en/v6/api#useroutes
|
|
431
447
|
*/
|
|
432
448
|
|
|
433
449
|
function useRoutes(routes, locationArg) {
|
|
@@ -465,7 +481,7 @@ function useRoutes(routes, locationArg) {
|
|
|
465
481
|
// );
|
|
466
482
|
// }
|
|
467
483
|
let parentPath = parentRoute && parentRoute.path || "";
|
|
468
|
-
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 + "/*") + "\">."));
|
|
469
485
|
}
|
|
470
486
|
|
|
471
487
|
let locationFromContext = useLocation();
|
|
@@ -506,7 +522,7 @@ function useRoutes(routes, locationArg) {
|
|
|
506
522
|
* either a `<Route>` element or an array of them. Used internally by
|
|
507
523
|
* `<Routes>` to create a route config from its children.
|
|
508
524
|
*
|
|
509
|
-
* @see https://reactrouter.com/api
|
|
525
|
+
* @see https://reactrouter.com/docs/en/v6/api#createroutesfromchildren
|
|
510
526
|
*/
|
|
511
527
|
|
|
512
528
|
function createRoutesFromChildren(children) {
|
|
@@ -524,6 +540,7 @@ function createRoutesFromChildren(children) {
|
|
|
524
540
|
return;
|
|
525
541
|
}
|
|
526
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;
|
|
527
544
|
let route = {
|
|
528
545
|
caseSensitive: element.props.caseSensitive,
|
|
529
546
|
element: element.props.element,
|
|
@@ -546,7 +563,7 @@ function createRoutesFromChildren(children) {
|
|
|
546
563
|
/**
|
|
547
564
|
* Returns a path with params interpolated.
|
|
548
565
|
*
|
|
549
|
-
* @see https://reactrouter.com/api
|
|
566
|
+
* @see https://reactrouter.com/docs/en/v6/api#generatepath
|
|
550
567
|
*/
|
|
551
568
|
function generatePath(path, params) {
|
|
552
569
|
if (params === void 0) {
|
|
@@ -565,7 +582,7 @@ function generatePath(path, params) {
|
|
|
565
582
|
/**
|
|
566
583
|
* Matches the given routes to a location and returns the match data.
|
|
567
584
|
*
|
|
568
|
-
* @see https://reactrouter.com/api
|
|
585
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchroutes
|
|
569
586
|
*/
|
|
570
587
|
function matchRoutes(routes, locationArg, basename) {
|
|
571
588
|
if (basename === void 0) {
|
|
@@ -584,7 +601,7 @@ function matchRoutes(routes, locationArg, basename) {
|
|
|
584
601
|
let matches = null;
|
|
585
602
|
|
|
586
603
|
for (let i = 0; matches == null && i < branches.length; ++i) {
|
|
587
|
-
matches = matchRouteBranch(branches[i],
|
|
604
|
+
matches = matchRouteBranch(branches[i], pathname);
|
|
588
605
|
}
|
|
589
606
|
|
|
590
607
|
return matches;
|
|
@@ -607,7 +624,8 @@ function flattenRoutes(routes, branches, parentsMeta, parentPath) {
|
|
|
607
624
|
let meta = {
|
|
608
625
|
relativePath: route.path || "",
|
|
609
626
|
caseSensitive: route.caseSensitive === true,
|
|
610
|
-
childrenIndex: index
|
|
627
|
+
childrenIndex: index,
|
|
628
|
+
route
|
|
611
629
|
};
|
|
612
630
|
|
|
613
631
|
if (meta.relativePath.startsWith("/")) {
|
|
@@ -680,9 +698,7 @@ function compareIndexes(a, b) {
|
|
|
680
698
|
0;
|
|
681
699
|
}
|
|
682
700
|
|
|
683
|
-
function matchRouteBranch(branch,
|
|
684
|
-
routesArg, pathname) {
|
|
685
|
-
let routes = routesArg;
|
|
701
|
+
function matchRouteBranch(branch, pathname) {
|
|
686
702
|
let {
|
|
687
703
|
routesMeta
|
|
688
704
|
} = branch;
|
|
@@ -701,7 +717,7 @@ routesArg, pathname) {
|
|
|
701
717
|
}, remainingPathname);
|
|
702
718
|
if (!match) return null;
|
|
703
719
|
Object.assign(matchedParams, match.params);
|
|
704
|
-
let route =
|
|
720
|
+
let route = meta.route;
|
|
705
721
|
matches.push({
|
|
706
722
|
params: matchedParams,
|
|
707
723
|
pathname: joinPaths([matchedPathname, match.pathname]),
|
|
@@ -712,8 +728,6 @@ routesArg, pathname) {
|
|
|
712
728
|
if (match.pathnameBase !== "/") {
|
|
713
729
|
matchedPathname = joinPaths([matchedPathname, match.pathnameBase]);
|
|
714
730
|
}
|
|
715
|
-
|
|
716
|
-
routes = route.children;
|
|
717
731
|
}
|
|
718
732
|
|
|
719
733
|
return matches;
|
|
@@ -752,7 +766,7 @@ function _renderMatches(matches, parentMatches) {
|
|
|
752
766
|
* Performs pattern matching on a URL pathname and returns information about
|
|
753
767
|
* the match.
|
|
754
768
|
*
|
|
755
|
-
* @see https://reactrouter.com/api
|
|
769
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchpath
|
|
756
770
|
*/
|
|
757
771
|
function matchPath(pattern, pathname) {
|
|
758
772
|
if (typeof pattern === "string") {
|
|
@@ -813,10 +827,10 @@ function compilePath(path, caseSensitive, end) {
|
|
|
813
827
|
: "(?:\\/(.+)|\\/*)$"; // Don't include the / in params["*"]
|
|
814
828
|
} else {
|
|
815
829
|
regexpSource += end ? "\\/*$" // When matching to the end, ignore trailing slashes
|
|
816
|
-
: // Otherwise,
|
|
817
|
-
// 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
|
|
818
832
|
// route "/home" should not match "/home2".
|
|
819
|
-
"(?:\\b
|
|
833
|
+
"(?:\\b|\\/|$)";
|
|
820
834
|
}
|
|
821
835
|
|
|
822
836
|
let matcher = new RegExp(regexpSource, caseSensitive ? undefined : "i");
|
|
@@ -834,7 +848,7 @@ function safelyDecodeURIComponent(value, paramName) {
|
|
|
834
848
|
/**
|
|
835
849
|
* Returns a resolved path object relative to the given pathname.
|
|
836
850
|
*
|
|
837
|
-
* @see https://reactrouter.com/api
|
|
851
|
+
* @see https://reactrouter.com/docs/en/v6/api#resolvepath
|
|
838
852
|
*/
|
|
839
853
|
|
|
840
854
|
|
|
@@ -944,5 +958,5 @@ const normalizeSearch = search => !search || search === "?" ? "" : search.starts
|
|
|
944
958
|
|
|
945
959
|
const normalizeHash = hash => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash; ///////////////////////////////////////////////////////////////////////////////
|
|
946
960
|
|
|
947
|
-
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, 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 };
|
|
948
962
|
//# sourceMappingURL=index.js.map
|