react-router 6.0.0-beta.7 → 6.0.2
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 +35 -27
- package/index.js +60 -34
- package/index.js.map +1 -1
- package/main.js +1 -1
- package/package.json +4 -2
- package/react-router.development.js +60 -34
- 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 +60 -33
- 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
|
*
|
|
@@ -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,7 +52,7 @@ 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,7 +60,7 @@ export interface OutletProps {
|
|
|
59
60
|
/**
|
|
60
61
|
* Renders the child route's element, if there is one.
|
|
61
62
|
*
|
|
62
|
-
* @see https://reactrouter.com/api
|
|
63
|
+
* @see https://reactrouter.com/docs/en/v6/api#outlet
|
|
63
64
|
*/
|
|
64
65
|
export declare function Outlet(_props: OutletProps): React.ReactElement | null;
|
|
65
66
|
export interface RouteProps {
|
|
@@ -87,14 +88,14 @@ export interface IndexRouteProps {
|
|
|
87
88
|
/**
|
|
88
89
|
* Declares an element that should be rendered at a certain URL path.
|
|
89
90
|
*
|
|
90
|
-
* @see https://reactrouter.com/api
|
|
91
|
+
* @see https://reactrouter.com/docs/en/v6/api#route
|
|
91
92
|
*/
|
|
92
93
|
export declare function Route(_props: PathRouteProps | LayoutRouteProps | IndexRouteProps): React.ReactElement | null;
|
|
93
94
|
export interface RouterProps {
|
|
94
|
-
action?: Action;
|
|
95
95
|
basename?: string;
|
|
96
96
|
children?: React.ReactNode;
|
|
97
97
|
location: Partial<Location> | string;
|
|
98
|
+
navigationType?: NavigationType;
|
|
98
99
|
navigator: Navigator;
|
|
99
100
|
static?: boolean;
|
|
100
101
|
}
|
|
@@ -105,9 +106,9 @@ export interface RouterProps {
|
|
|
105
106
|
* router that is more specific to your environment such as a <BrowserRouter>
|
|
106
107
|
* in web browsers or a <StaticRouter> for server rendering.
|
|
107
108
|
*
|
|
108
|
-
* @see https://reactrouter.com/api
|
|
109
|
+
* @see https://reactrouter.com/docs/en/v6/api#router
|
|
109
110
|
*/
|
|
110
|
-
export declare function Router({
|
|
111
|
+
export declare function Router({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp }: RouterProps): React.ReactElement | null;
|
|
111
112
|
export interface RoutesProps {
|
|
112
113
|
children?: React.ReactNode;
|
|
113
114
|
location?: Partial<Location> | string;
|
|
@@ -116,20 +117,20 @@ export interface RoutesProps {
|
|
|
116
117
|
* A container for a nested tree of <Route> elements that renders the branch
|
|
117
118
|
* that best matches the current location.
|
|
118
119
|
*
|
|
119
|
-
* @see https://reactrouter.com/api
|
|
120
|
+
* @see https://reactrouter.com/docs/en/v6/api#routes
|
|
120
121
|
*/
|
|
121
122
|
export declare function Routes({ children, location }: RoutesProps): React.ReactElement | null;
|
|
122
123
|
/**
|
|
123
124
|
* Returns the full href for the given "to" value. This is useful for building
|
|
124
125
|
* custom links that are also accessible and preserve right-click behavior.
|
|
125
126
|
*
|
|
126
|
-
* @see https://reactrouter.com/api
|
|
127
|
+
* @see https://reactrouter.com/docs/en/v6/api#usehref
|
|
127
128
|
*/
|
|
128
129
|
export declare function useHref(to: To): string;
|
|
129
130
|
/**
|
|
130
131
|
* Returns true if this component is a descendant of a <Router>.
|
|
131
132
|
*
|
|
132
|
-
* @see https://reactrouter.com/api
|
|
133
|
+
* @see https://reactrouter.com/docs/en/v6/api#useinroutercontext
|
|
133
134
|
*/
|
|
134
135
|
export declare function useInRouterContext(): boolean;
|
|
135
136
|
/**
|
|
@@ -140,15 +141,22 @@ export declare function useInRouterContext(): boolean;
|
|
|
140
141
|
* "routing" in your app, and we'd like to know what your use case is. We may
|
|
141
142
|
* be able to provide something higher-level to better suit your needs.
|
|
142
143
|
*
|
|
143
|
-
* @see https://reactrouter.com/api
|
|
144
|
+
* @see https://reactrouter.com/docs/en/v6/api#uselocation
|
|
144
145
|
*/
|
|
145
146
|
export declare function useLocation(): Location;
|
|
147
|
+
/**
|
|
148
|
+
* Returns the current navigation action which describes how the router came to
|
|
149
|
+
* the current location, either by a pop, push, or replace on the history stack.
|
|
150
|
+
*
|
|
151
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigationtype
|
|
152
|
+
*/
|
|
153
|
+
export declare function useNavigationType(): NavigationType;
|
|
146
154
|
/**
|
|
147
155
|
* Returns true if the URL for the given "to" value matches the current URL.
|
|
148
156
|
* This is useful for components that need to know "active" state, e.g.
|
|
149
157
|
* <NavLink>.
|
|
150
158
|
*
|
|
151
|
-
* @see https://reactrouter.com/api
|
|
159
|
+
* @see https://reactrouter.com/docs/en/v6/api#usematch
|
|
152
160
|
*/
|
|
153
161
|
export declare function useMatch<ParamKey extends string = string>(pattern: PathPattern | string): PathMatch<ParamKey> | null;
|
|
154
162
|
/**
|
|
@@ -160,33 +168,33 @@ export interface NavigateFunction {
|
|
|
160
168
|
}
|
|
161
169
|
export interface NavigateOptions {
|
|
162
170
|
replace?: boolean;
|
|
163
|
-
state?:
|
|
171
|
+
state?: any;
|
|
164
172
|
}
|
|
165
173
|
/**
|
|
166
174
|
* Returns an imperative method for changing the location. Used by <Link>s, but
|
|
167
175
|
* may also be used by other elements to change the location.
|
|
168
176
|
*
|
|
169
|
-
* @see https://reactrouter.com/api
|
|
177
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigate
|
|
170
178
|
*/
|
|
171
179
|
export declare function useNavigate(): NavigateFunction;
|
|
172
180
|
/**
|
|
173
181
|
* Returns the element for the child route at this level of the route
|
|
174
182
|
* hierarchy. Used internally by <Outlet> to render child routes.
|
|
175
183
|
*
|
|
176
|
-
* @see https://reactrouter.com/api
|
|
184
|
+
* @see https://reactrouter.com/docs/en/v6/api#useoutlet
|
|
177
185
|
*/
|
|
178
186
|
export declare function useOutlet(): React.ReactElement | null;
|
|
179
187
|
/**
|
|
180
188
|
* Returns an object of key/value pairs of the dynamic params from the current
|
|
181
189
|
* URL that were matched by the route path.
|
|
182
190
|
*
|
|
183
|
-
* @see https://reactrouter.com/api
|
|
191
|
+
* @see https://reactrouter.com/docs/en/v6/api#useparams
|
|
184
192
|
*/
|
|
185
193
|
export declare function useParams<Key extends string = string>(): Readonly<Params<Key>>;
|
|
186
194
|
/**
|
|
187
195
|
* Resolves the pathname of the given `to` value against the current location.
|
|
188
196
|
*
|
|
189
|
-
* @see https://reactrouter.com/api
|
|
197
|
+
* @see https://reactrouter.com/docs/en/v6/api#useresolvedpath
|
|
190
198
|
*/
|
|
191
199
|
export declare function useResolvedPath(to: To): Path;
|
|
192
200
|
/**
|
|
@@ -195,7 +203,7 @@ export declare function useResolvedPath(to: To): Path;
|
|
|
195
203
|
* elements in the tree must render an <Outlet> to render their child route's
|
|
196
204
|
* element.
|
|
197
205
|
*
|
|
198
|
-
* @see https://reactrouter.com/api
|
|
206
|
+
* @see https://reactrouter.com/docs/en/v6/api#useroutes
|
|
199
207
|
*/
|
|
200
208
|
export declare function useRoutes(routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null;
|
|
201
209
|
/**
|
|
@@ -203,7 +211,7 @@ export declare function useRoutes(routes: RouteObject[], locationArg?: Partial<L
|
|
|
203
211
|
* either a `<Route>` element or an array of them. Used internally by
|
|
204
212
|
* `<Routes>` to create a route config from its children.
|
|
205
213
|
*
|
|
206
|
-
* @see https://reactrouter.com/api
|
|
214
|
+
* @see https://reactrouter.com/docs/en/v6/api#createroutesfromchildren
|
|
207
215
|
*/
|
|
208
216
|
export declare function createRoutesFromChildren(children: React.ReactNode): RouteObject[];
|
|
209
217
|
/**
|
|
@@ -226,7 +234,7 @@ export interface RouteObject {
|
|
|
226
234
|
/**
|
|
227
235
|
* Returns a path with params interpolated.
|
|
228
236
|
*
|
|
229
|
-
* @see https://reactrouter.com/api
|
|
237
|
+
* @see https://reactrouter.com/docs/en/v6/api#generatepath
|
|
230
238
|
*/
|
|
231
239
|
export declare function generatePath(path: string, params?: Params): string;
|
|
232
240
|
/**
|
|
@@ -253,7 +261,7 @@ export interface RouteMatch<ParamKey extends string = string> {
|
|
|
253
261
|
/**
|
|
254
262
|
* Matches the given routes to a location and returns the match data.
|
|
255
263
|
*
|
|
256
|
-
* @see https://reactrouter.com/api
|
|
264
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchroutes
|
|
257
265
|
*/
|
|
258
266
|
export declare function matchRoutes(routes: RouteObject[], locationArg: Partial<Location> | string, basename?: string): RouteMatch[] | null;
|
|
259
267
|
/**
|
|
@@ -305,13 +313,13 @@ export interface PathMatch<ParamKey extends string = string> {
|
|
|
305
313
|
* Performs pattern matching on a URL pathname and returns information about
|
|
306
314
|
* the match.
|
|
307
315
|
*
|
|
308
|
-
* @see https://reactrouter.com/api
|
|
316
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchpath
|
|
309
317
|
*/
|
|
310
318
|
export declare function matchPath<ParamKey extends string = string>(pattern: PathPattern | string, pathname: string): PathMatch<ParamKey> | null;
|
|
311
319
|
/**
|
|
312
320
|
* Returns a resolved path object relative to the given pathname.
|
|
313
321
|
*
|
|
314
|
-
* @see https://reactrouter.com/api
|
|
322
|
+
* @see https://reactrouter.com/docs/en/v6/api#resolvepath
|
|
315
323
|
*/
|
|
316
324
|
export declare function resolvePath(to: To, fromPathname?: string): Path;
|
|
317
325
|
/** @internal */
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v6.0.
|
|
2
|
+
* React Router v6.0.2
|
|
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,7 +145,7 @@ 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
150
|
function Outlet(_props) {
|
|
151
151
|
return useOutlet();
|
|
@@ -154,7 +154,7 @@ function Outlet(_props) {
|
|
|
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) {
|
|
@@ -260,20 +260,29 @@ function useHref(to) {
|
|
|
260
260
|
basename,
|
|
261
261
|
navigator
|
|
262
262
|
} = useContext(NavigationContext);
|
|
263
|
-
let
|
|
263
|
+
let {
|
|
264
|
+
hash,
|
|
265
|
+
pathname,
|
|
266
|
+
search
|
|
267
|
+
} = useResolvedPath(to);
|
|
268
|
+
let joinedPathname = pathname;
|
|
264
269
|
|
|
265
270
|
if (basename !== "/") {
|
|
266
271
|
let toPathname = getToPathname(to);
|
|
267
272
|
let endsWithSlash = toPathname != null && toPathname.endsWith("/");
|
|
268
|
-
|
|
273
|
+
joinedPathname = pathname === "/" ? basename + (endsWithSlash ? "/" : "") : joinPaths([basename, pathname]);
|
|
269
274
|
}
|
|
270
275
|
|
|
271
|
-
return navigator.createHref(
|
|
276
|
+
return navigator.createHref({
|
|
277
|
+
pathname: joinedPathname,
|
|
278
|
+
search,
|
|
279
|
+
hash
|
|
280
|
+
});
|
|
272
281
|
}
|
|
273
282
|
/**
|
|
274
283
|
* Returns true if this component is a descendant of a <Router>.
|
|
275
284
|
*
|
|
276
|
-
* @see https://reactrouter.com/api
|
|
285
|
+
* @see https://reactrouter.com/docs/en/v6/api#useinroutercontext
|
|
277
286
|
*/
|
|
278
287
|
|
|
279
288
|
function useInRouterContext() {
|
|
@@ -287,7 +296,7 @@ function useInRouterContext() {
|
|
|
287
296
|
* "routing" in your app, and we'd like to know what your use case is. We may
|
|
288
297
|
* be able to provide something higher-level to better suit your needs.
|
|
289
298
|
*
|
|
290
|
-
* @see https://reactrouter.com/api
|
|
299
|
+
* @see https://reactrouter.com/docs/en/v6/api#uselocation
|
|
291
300
|
*/
|
|
292
301
|
|
|
293
302
|
function useLocation() {
|
|
@@ -296,12 +305,22 @@ function useLocation() {
|
|
|
296
305
|
"useLocation() may be used only in the context of a <Router> component.") : invariant(false) : void 0;
|
|
297
306
|
return useContext(LocationContext).location;
|
|
298
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* Returns the current navigation action which describes how the router came to
|
|
310
|
+
* the current location, either by a pop, push, or replace on the history stack.
|
|
311
|
+
*
|
|
312
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigationtype
|
|
313
|
+
*/
|
|
314
|
+
|
|
315
|
+
function useNavigationType() {
|
|
316
|
+
return useContext(LocationContext).navigationType;
|
|
317
|
+
}
|
|
299
318
|
/**
|
|
300
319
|
* Returns true if the URL for the given "to" value matches the current URL.
|
|
301
320
|
* This is useful for components that need to know "active" state, e.g.
|
|
302
321
|
* <NavLink>.
|
|
303
322
|
*
|
|
304
|
-
* @see https://reactrouter.com/api
|
|
323
|
+
* @see https://reactrouter.com/docs/en/v6/api#usematch
|
|
305
324
|
*/
|
|
306
325
|
|
|
307
326
|
function useMatch(pattern) {
|
|
@@ -318,7 +337,7 @@ function useMatch(pattern) {
|
|
|
318
337
|
* Returns an imperative method for changing the location. Used by <Link>s, but
|
|
319
338
|
* may also be used by other elements to change the location.
|
|
320
339
|
*
|
|
321
|
-
* @see https://reactrouter.com/api
|
|
340
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigate
|
|
322
341
|
*/
|
|
323
342
|
function useNavigate() {
|
|
324
343
|
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
@@ -366,7 +385,7 @@ function useNavigate() {
|
|
|
366
385
|
* Returns the element for the child route at this level of the route
|
|
367
386
|
* hierarchy. Used internally by <Outlet> to render child routes.
|
|
368
387
|
*
|
|
369
|
-
* @see https://reactrouter.com/api
|
|
388
|
+
* @see https://reactrouter.com/docs/en/v6/api#useoutlet
|
|
370
389
|
*/
|
|
371
390
|
|
|
372
391
|
function useOutlet() {
|
|
@@ -376,7 +395,7 @@ function useOutlet() {
|
|
|
376
395
|
* Returns an object of key/value pairs of the dynamic params from the current
|
|
377
396
|
* URL that were matched by the route path.
|
|
378
397
|
*
|
|
379
|
-
* @see https://reactrouter.com/api
|
|
398
|
+
* @see https://reactrouter.com/docs/en/v6/api#useparams
|
|
380
399
|
*/
|
|
381
400
|
|
|
382
401
|
function useParams() {
|
|
@@ -389,7 +408,7 @@ function useParams() {
|
|
|
389
408
|
/**
|
|
390
409
|
* Resolves the pathname of the given `to` value against the current location.
|
|
391
410
|
*
|
|
392
|
-
* @see https://reactrouter.com/api
|
|
411
|
+
* @see https://reactrouter.com/docs/en/v6/api#useresolvedpath
|
|
393
412
|
*/
|
|
394
413
|
|
|
395
414
|
function useResolvedPath(to) {
|
|
@@ -408,7 +427,7 @@ function useResolvedPath(to) {
|
|
|
408
427
|
* elements in the tree must render an <Outlet> to render their child route's
|
|
409
428
|
* element.
|
|
410
429
|
*
|
|
411
|
-
* @see https://reactrouter.com/api
|
|
430
|
+
* @see https://reactrouter.com/docs/en/v6/api#useroutes
|
|
412
431
|
*/
|
|
413
432
|
|
|
414
433
|
function useRoutes(routes, locationArg) {
|
|
@@ -470,12 +489,13 @@ function useRoutes(routes, locationArg) {
|
|
|
470
489
|
|
|
471
490
|
if (process.env.NODE_ENV !== "production") {
|
|
472
491
|
process.env.NODE_ENV !== "production" ? warning(parentRoute || matches != null, "No routes matched location \"" + location.pathname + location.search + location.hash + "\" ") : void 0;
|
|
492
|
+
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;
|
|
473
493
|
}
|
|
474
494
|
|
|
475
495
|
return _renderMatches(matches && matches.map(match => Object.assign({}, match, {
|
|
476
496
|
params: Object.assign({}, parentParams, match.params),
|
|
477
497
|
pathname: joinPaths([parentPathnameBase, match.pathname]),
|
|
478
|
-
pathnameBase: joinPaths([parentPathnameBase, match.pathnameBase])
|
|
498
|
+
pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([parentPathnameBase, match.pathnameBase])
|
|
479
499
|
})), parentMatches);
|
|
480
500
|
} ///////////////////////////////////////////////////////////////////////////////
|
|
481
501
|
// UTILS
|
|
@@ -486,7 +506,7 @@ function useRoutes(routes, locationArg) {
|
|
|
486
506
|
* either a `<Route>` element or an array of them. Used internally by
|
|
487
507
|
* `<Routes>` to create a route config from its children.
|
|
488
508
|
*
|
|
489
|
-
* @see https://reactrouter.com/api
|
|
509
|
+
* @see https://reactrouter.com/docs/en/v6/api#createroutesfromchildren
|
|
490
510
|
*/
|
|
491
511
|
|
|
492
512
|
function createRoutesFromChildren(children) {
|
|
@@ -504,6 +524,7 @@ function createRoutesFromChildren(children) {
|
|
|
504
524
|
return;
|
|
505
525
|
}
|
|
506
526
|
|
|
527
|
+
!(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;
|
|
507
528
|
let route = {
|
|
508
529
|
caseSensitive: element.props.caseSensitive,
|
|
509
530
|
element: element.props.element,
|
|
@@ -526,7 +547,7 @@ function createRoutesFromChildren(children) {
|
|
|
526
547
|
/**
|
|
527
548
|
* Returns a path with params interpolated.
|
|
528
549
|
*
|
|
529
|
-
* @see https://reactrouter.com/api
|
|
550
|
+
* @see https://reactrouter.com/docs/en/v6/api#generatepath
|
|
530
551
|
*/
|
|
531
552
|
function generatePath(path, params) {
|
|
532
553
|
if (params === void 0) {
|
|
@@ -545,7 +566,7 @@ function generatePath(path, params) {
|
|
|
545
566
|
/**
|
|
546
567
|
* Matches the given routes to a location and returns the match data.
|
|
547
568
|
*
|
|
548
|
-
* @see https://reactrouter.com/api
|
|
569
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchroutes
|
|
549
570
|
*/
|
|
550
571
|
function matchRoutes(routes, locationArg, basename) {
|
|
551
572
|
if (basename === void 0) {
|
|
@@ -613,7 +634,7 @@ function flattenRoutes(routes, branches, parentsMeta, parentPath) {
|
|
|
613
634
|
|
|
614
635
|
branches.push({
|
|
615
636
|
path,
|
|
616
|
-
score: computeScore(path),
|
|
637
|
+
score: computeScore(path, route.index),
|
|
617
638
|
routesMeta
|
|
618
639
|
});
|
|
619
640
|
});
|
|
@@ -626,14 +647,15 @@ function rankRouteBranches(branches) {
|
|
|
626
647
|
}
|
|
627
648
|
|
|
628
649
|
const paramRe = /^:\w+$/;
|
|
629
|
-
const dynamicSegmentValue =
|
|
650
|
+
const dynamicSegmentValue = 3;
|
|
651
|
+
const indexRouteValue = 2;
|
|
630
652
|
const emptySegmentValue = 1;
|
|
631
653
|
const staticSegmentValue = 10;
|
|
632
654
|
const splatPenalty = -2;
|
|
633
655
|
|
|
634
656
|
const isSplat = s => s === "*";
|
|
635
657
|
|
|
636
|
-
function computeScore(path) {
|
|
658
|
+
function computeScore(path, index) {
|
|
637
659
|
let segments = path.split("/");
|
|
638
660
|
let initialScore = segments.length;
|
|
639
661
|
|
|
@@ -641,6 +663,10 @@ function computeScore(path) {
|
|
|
641
663
|
initialScore += splatPenalty;
|
|
642
664
|
}
|
|
643
665
|
|
|
666
|
+
if (index) {
|
|
667
|
+
initialScore += indexRouteValue;
|
|
668
|
+
}
|
|
669
|
+
|
|
644
670
|
return segments.filter(s => !isSplat(s)).reduce((score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue), initialScore);
|
|
645
671
|
}
|
|
646
672
|
|
|
@@ -710,7 +736,7 @@ function _renderMatches(matches, parentMatches) {
|
|
|
710
736
|
if (matches == null) return null;
|
|
711
737
|
return matches.reduceRight((outlet, match, index) => {
|
|
712
738
|
return /*#__PURE__*/createElement(RouteContext.Provider, {
|
|
713
|
-
children: match.route.element
|
|
739
|
+
children: match.route.element !== undefined ? match.route.element : /*#__PURE__*/createElement(Outlet, null),
|
|
714
740
|
value: {
|
|
715
741
|
outlet,
|
|
716
742
|
matches: parentMatches.concat(matches.slice(0, index + 1))
|
|
@@ -727,7 +753,7 @@ function _renderMatches(matches, parentMatches) {
|
|
|
727
753
|
* Performs pattern matching on a URL pathname and returns information about
|
|
728
754
|
* the match.
|
|
729
755
|
*
|
|
730
|
-
* @see https://reactrouter.com/api
|
|
756
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchpath
|
|
731
757
|
*/
|
|
732
758
|
function matchPath(pattern, pathname) {
|
|
733
759
|
if (typeof pattern === "string") {
|
|
@@ -809,7 +835,7 @@ function safelyDecodeURIComponent(value, paramName) {
|
|
|
809
835
|
/**
|
|
810
836
|
* Returns a resolved path object relative to the given pathname.
|
|
811
837
|
*
|
|
812
|
-
* @see https://reactrouter.com/api
|
|
838
|
+
* @see https://reactrouter.com/docs/en/v6/api#resolvepath
|
|
813
839
|
*/
|
|
814
840
|
|
|
815
841
|
|
|
@@ -919,5 +945,5 @@ const normalizeSearch = search => !search || search === "?" ? "" : search.starts
|
|
|
919
945
|
|
|
920
946
|
const normalizeHash = hash => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash; ///////////////////////////////////////////////////////////////////////////////
|
|
921
947
|
|
|
922
|
-
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 };
|
|
948
|
+
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 };
|
|
923
949
|
//# sourceMappingURL=index.js.map
|