react-router 6.0.0-beta.6 → 6.0.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 +39 -41
- package/index.js +139 -122
- package/index.js.map +1 -1
- package/main.js +1 -1
- package/package.json +4 -9
- package/react-router.development.js +135 -100
- 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 +139 -122
- 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.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v6.0.
|
|
2
|
+
* React Router v6.0.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -11,24 +11,6 @@
|
|
|
11
11
|
import { createContext, useRef, useState, useLayoutEffect, createElement, useContext, useEffect, useMemo, useCallback, Children, isValidElement, Fragment } from 'react';
|
|
12
12
|
import { createMemoryHistory, Action, parsePath } from 'history';
|
|
13
13
|
|
|
14
|
-
function _extends() {
|
|
15
|
-
_extends = Object.assign || function (target) {
|
|
16
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
17
|
-
var source = arguments[i];
|
|
18
|
-
|
|
19
|
-
for (var key in source) {
|
|
20
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
21
|
-
target[key] = source[key];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return target;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
return _extends.apply(this, arguments);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
14
|
function invariant(cond, message) {
|
|
33
15
|
if (!cond) throw new Error(message);
|
|
34
16
|
}
|
|
@@ -85,10 +67,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
85
67
|
|
|
86
68
|
const RouteContext = /*#__PURE__*/createContext({
|
|
87
69
|
outlet: null,
|
|
88
|
-
|
|
89
|
-
pathname: "/",
|
|
90
|
-
pathnameBase: "/",
|
|
91
|
-
route: null
|
|
70
|
+
matches: []
|
|
92
71
|
});
|
|
93
72
|
|
|
94
73
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -101,7 +80,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
101
80
|
/**
|
|
102
81
|
* A <Router> that stores all entries in memory.
|
|
103
82
|
*
|
|
104
|
-
* @see https://reactrouter.com/api
|
|
83
|
+
* @see https://reactrouter.com/docs/en/v6/api#memoryrouter
|
|
105
84
|
*/
|
|
106
85
|
function MemoryRouter(_ref) {
|
|
107
86
|
let {
|
|
@@ -128,8 +107,8 @@ function MemoryRouter(_ref) {
|
|
|
128
107
|
return /*#__PURE__*/createElement(Router, {
|
|
129
108
|
basename: basename,
|
|
130
109
|
children: children,
|
|
131
|
-
action: state.action,
|
|
132
110
|
location: state.location,
|
|
111
|
+
navigationType: state.action,
|
|
133
112
|
navigator: history
|
|
134
113
|
});
|
|
135
114
|
}
|
|
@@ -141,7 +120,7 @@ function MemoryRouter(_ref) {
|
|
|
141
120
|
* able to use hooks. In functional components, we recommend you use the
|
|
142
121
|
* `useNavigate` hook instead.
|
|
143
122
|
*
|
|
144
|
-
* @see https://reactrouter.com/api
|
|
123
|
+
* @see https://reactrouter.com/docs/en/v6/api#navigate
|
|
145
124
|
*/
|
|
146
125
|
function Navigate(_ref2) {
|
|
147
126
|
let {
|
|
@@ -166,7 +145,7 @@ function Navigate(_ref2) {
|
|
|
166
145
|
/**
|
|
167
146
|
* Renders the child route's element, if there is one.
|
|
168
147
|
*
|
|
169
|
-
* @see https://reactrouter.com/api
|
|
148
|
+
* @see https://reactrouter.com/docs/en/v6/api#outlet
|
|
170
149
|
*/
|
|
171
150
|
function Outlet(_props) {
|
|
172
151
|
return useOutlet();
|
|
@@ -175,7 +154,7 @@ function Outlet(_props) {
|
|
|
175
154
|
/**
|
|
176
155
|
* Declares an element that should be rendered at a certain URL path.
|
|
177
156
|
*
|
|
178
|
-
* @see https://reactrouter.com/api
|
|
157
|
+
* @see https://reactrouter.com/docs/en/v6/api#route
|
|
179
158
|
*/
|
|
180
159
|
function Route(_props) {
|
|
181
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) ;
|
|
@@ -188,14 +167,14 @@ function Route(_props) {
|
|
|
188
167
|
* router that is more specific to your environment such as a <BrowserRouter>
|
|
189
168
|
* in web browsers or a <StaticRouter> for server rendering.
|
|
190
169
|
*
|
|
191
|
-
* @see https://reactrouter.com/api
|
|
170
|
+
* @see https://reactrouter.com/docs/en/v6/api#router
|
|
192
171
|
*/
|
|
193
172
|
function Router(_ref3) {
|
|
194
173
|
let {
|
|
195
|
-
action = Action.Pop,
|
|
196
174
|
basename: basenameProp = "/",
|
|
197
175
|
children = null,
|
|
198
176
|
location: locationProp,
|
|
177
|
+
navigationType = Action.Pop,
|
|
199
178
|
navigator,
|
|
200
179
|
static: staticProp = false
|
|
201
180
|
} = _ref3;
|
|
@@ -244,8 +223,8 @@ function Router(_ref3) {
|
|
|
244
223
|
}, /*#__PURE__*/createElement(LocationContext.Provider, {
|
|
245
224
|
children: children,
|
|
246
225
|
value: {
|
|
247
|
-
|
|
248
|
-
|
|
226
|
+
location,
|
|
227
|
+
navigationType
|
|
249
228
|
}
|
|
250
229
|
}));
|
|
251
230
|
}
|
|
@@ -254,7 +233,7 @@ function Router(_ref3) {
|
|
|
254
233
|
* A container for a nested tree of <Route> elements that renders the branch
|
|
255
234
|
* that best matches the current location.
|
|
256
235
|
*
|
|
257
|
-
* @see https://reactrouter.com/api
|
|
236
|
+
* @see https://reactrouter.com/docs/en/v6/api#routes
|
|
258
237
|
*/
|
|
259
238
|
function Routes(_ref4) {
|
|
260
239
|
let {
|
|
@@ -266,48 +245,11 @@ function Routes(_ref4) {
|
|
|
266
245
|
// HOOKS
|
|
267
246
|
///////////////////////////////////////////////////////////////////////////////
|
|
268
247
|
|
|
269
|
-
/**
|
|
270
|
-
* Blocks all navigation attempts. This is useful for preventing the page from
|
|
271
|
-
* changing until some condition is met, like saving form data.
|
|
272
|
-
*
|
|
273
|
-
* @see https://reactrouter.com/api/useBlocker
|
|
274
|
-
*/
|
|
275
|
-
|
|
276
|
-
function useBlocker(blocker, when) {
|
|
277
|
-
if (when === void 0) {
|
|
278
|
-
when = true;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
282
|
-
// router loaded. We can help them understand how to avoid that.
|
|
283
|
-
"useBlocker() may be used only in the context of a <Router> component.") : invariant(false) : void 0;
|
|
284
|
-
let {
|
|
285
|
-
navigator
|
|
286
|
-
} = useContext(NavigationContext);
|
|
287
|
-
useEffect(() => {
|
|
288
|
-
if (!when) return;
|
|
289
|
-
let unblock = navigator.block(tx => {
|
|
290
|
-
let autoUnblockingTx = _extends({}, tx, {
|
|
291
|
-
retry() {
|
|
292
|
-
// Automatically unblock the transition so it can play all the way
|
|
293
|
-
// through before retrying it. TODO: Figure out how to re-enable
|
|
294
|
-
// this block if the transition is cancelled for some reason.
|
|
295
|
-
unblock();
|
|
296
|
-
tx.retry();
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
blocker(autoUnblockingTx);
|
|
302
|
-
});
|
|
303
|
-
return unblock;
|
|
304
|
-
}, [navigator, blocker, when]);
|
|
305
|
-
}
|
|
306
248
|
/**
|
|
307
249
|
* Returns the full href for the given "to" value. This is useful for building
|
|
308
250
|
* custom links that are also accessible and preserve right-click behavior.
|
|
309
251
|
*
|
|
310
|
-
* @see https://reactrouter.com/api
|
|
252
|
+
* @see https://reactrouter.com/docs/en/v6/api#usehref
|
|
311
253
|
*/
|
|
312
254
|
|
|
313
255
|
function useHref(to) {
|
|
@@ -318,20 +260,29 @@ function useHref(to) {
|
|
|
318
260
|
basename,
|
|
319
261
|
navigator
|
|
320
262
|
} = useContext(NavigationContext);
|
|
321
|
-
let
|
|
263
|
+
let {
|
|
264
|
+
hash,
|
|
265
|
+
pathname,
|
|
266
|
+
search
|
|
267
|
+
} = useResolvedPath(to);
|
|
268
|
+
let joinedPathname = pathname;
|
|
322
269
|
|
|
323
270
|
if (basename !== "/") {
|
|
324
271
|
let toPathname = getToPathname(to);
|
|
325
272
|
let endsWithSlash = toPathname != null && toPathname.endsWith("/");
|
|
326
|
-
|
|
273
|
+
joinedPathname = pathname === "/" ? basename + (endsWithSlash ? "/" : "") : joinPaths([basename, pathname]);
|
|
327
274
|
}
|
|
328
275
|
|
|
329
|
-
return navigator.createHref(
|
|
276
|
+
return navigator.createHref({
|
|
277
|
+
pathname: joinedPathname,
|
|
278
|
+
search,
|
|
279
|
+
hash
|
|
280
|
+
});
|
|
330
281
|
}
|
|
331
282
|
/**
|
|
332
283
|
* Returns true if this component is a descendant of a <Router>.
|
|
333
284
|
*
|
|
334
|
-
* @see https://reactrouter.com/api
|
|
285
|
+
* @see https://reactrouter.com/docs/en/v6/api#useinroutercontext
|
|
335
286
|
*/
|
|
336
287
|
|
|
337
288
|
function useInRouterContext() {
|
|
@@ -345,7 +296,7 @@ function useInRouterContext() {
|
|
|
345
296
|
* "routing" in your app, and we'd like to know what your use case is. We may
|
|
346
297
|
* be able to provide something higher-level to better suit your needs.
|
|
347
298
|
*
|
|
348
|
-
* @see https://reactrouter.com/api
|
|
299
|
+
* @see https://reactrouter.com/docs/en/v6/api#uselocation
|
|
349
300
|
*/
|
|
350
301
|
|
|
351
302
|
function useLocation() {
|
|
@@ -354,12 +305,22 @@ function useLocation() {
|
|
|
354
305
|
"useLocation() may be used only in the context of a <Router> component.") : invariant(false) : void 0;
|
|
355
306
|
return useContext(LocationContext).location;
|
|
356
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
|
+
}
|
|
357
318
|
/**
|
|
358
319
|
* Returns true if the URL for the given "to" value matches the current URL.
|
|
359
320
|
* This is useful for components that need to know "active" state, e.g.
|
|
360
321
|
* <NavLink>.
|
|
361
322
|
*
|
|
362
|
-
* @see https://reactrouter.com/api
|
|
323
|
+
* @see https://reactrouter.com/docs/en/v6/api#usematch
|
|
363
324
|
*/
|
|
364
325
|
|
|
365
326
|
function useMatch(pattern) {
|
|
@@ -376,7 +337,7 @@ function useMatch(pattern) {
|
|
|
376
337
|
* Returns an imperative method for changing the location. Used by <Link>s, but
|
|
377
338
|
* may also be used by other elements to change the location.
|
|
378
339
|
*
|
|
379
|
-
* @see https://reactrouter.com/api
|
|
340
|
+
* @see https://reactrouter.com/docs/en/v6/api#usenavigate
|
|
380
341
|
*/
|
|
381
342
|
function useNavigate() {
|
|
382
343
|
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
@@ -387,11 +348,12 @@ function useNavigate() {
|
|
|
387
348
|
navigator
|
|
388
349
|
} = useContext(NavigationContext);
|
|
389
350
|
let {
|
|
390
|
-
|
|
351
|
+
matches
|
|
391
352
|
} = useContext(RouteContext);
|
|
392
353
|
let {
|
|
393
354
|
pathname: locationPathname
|
|
394
355
|
} = useLocation();
|
|
356
|
+
let routePathnamesJson = JSON.stringify(matches.map(match => match.pathnameBase));
|
|
395
357
|
let activeRef = useRef(false);
|
|
396
358
|
useEffect(() => {
|
|
397
359
|
activeRef.current = true;
|
|
@@ -409,21 +371,21 @@ function useNavigate() {
|
|
|
409
371
|
return;
|
|
410
372
|
}
|
|
411
373
|
|
|
412
|
-
let path = resolveTo(to,
|
|
374
|
+
let path = resolveTo(to, JSON.parse(routePathnamesJson), locationPathname);
|
|
413
375
|
|
|
414
376
|
if (basename !== "/") {
|
|
415
377
|
path.pathname = joinPaths([basename, path.pathname]);
|
|
416
378
|
}
|
|
417
379
|
|
|
418
380
|
(!!options.replace ? navigator.replace : navigator.push)(path, options.state);
|
|
419
|
-
}, [basename, navigator,
|
|
381
|
+
}, [basename, navigator, routePathnamesJson, locationPathname]);
|
|
420
382
|
return navigate;
|
|
421
383
|
}
|
|
422
384
|
/**
|
|
423
385
|
* Returns the element for the child route at this level of the route
|
|
424
386
|
* hierarchy. Used internally by <Outlet> to render child routes.
|
|
425
387
|
*
|
|
426
|
-
* @see https://reactrouter.com/api
|
|
388
|
+
* @see https://reactrouter.com/docs/en/v6/api#useoutlet
|
|
427
389
|
*/
|
|
428
390
|
|
|
429
391
|
function useOutlet() {
|
|
@@ -433,26 +395,31 @@ function useOutlet() {
|
|
|
433
395
|
* Returns an object of key/value pairs of the dynamic params from the current
|
|
434
396
|
* URL that were matched by the route path.
|
|
435
397
|
*
|
|
436
|
-
* @see https://reactrouter.com/api
|
|
398
|
+
* @see https://reactrouter.com/docs/en/v6/api#useparams
|
|
437
399
|
*/
|
|
438
400
|
|
|
439
401
|
function useParams() {
|
|
440
|
-
|
|
402
|
+
let {
|
|
403
|
+
matches
|
|
404
|
+
} = useContext(RouteContext);
|
|
405
|
+
let routeMatch = matches[matches.length - 1];
|
|
406
|
+
return routeMatch ? routeMatch.params : {};
|
|
441
407
|
}
|
|
442
408
|
/**
|
|
443
409
|
* Resolves the pathname of the given `to` value against the current location.
|
|
444
410
|
*
|
|
445
|
-
* @see https://reactrouter.com/api
|
|
411
|
+
* @see https://reactrouter.com/docs/en/v6/api#useresolvedpath
|
|
446
412
|
*/
|
|
447
413
|
|
|
448
414
|
function useResolvedPath(to) {
|
|
449
415
|
let {
|
|
450
|
-
|
|
416
|
+
matches
|
|
451
417
|
} = useContext(RouteContext);
|
|
452
418
|
let {
|
|
453
419
|
pathname: locationPathname
|
|
454
420
|
} = useLocation();
|
|
455
|
-
|
|
421
|
+
let routePathnamesJson = JSON.stringify(matches.map(match => match.pathnameBase));
|
|
422
|
+
return useMemo(() => resolveTo(to, JSON.parse(routePathnamesJson), locationPathname), [to, routePathnamesJson, locationPathname]);
|
|
456
423
|
}
|
|
457
424
|
/**
|
|
458
425
|
* Returns the element of the route that matched the current location, prepared
|
|
@@ -460,7 +427,7 @@ function useResolvedPath(to) {
|
|
|
460
427
|
* elements in the tree must render an <Outlet> to render their child route's
|
|
461
428
|
* element.
|
|
462
429
|
*
|
|
463
|
-
* @see https://reactrouter.com/api
|
|
430
|
+
* @see https://reactrouter.com/docs/en/v6/api#useroutes
|
|
464
431
|
*/
|
|
465
432
|
|
|
466
433
|
function useRoutes(routes, locationArg) {
|
|
@@ -468,11 +435,13 @@ function useRoutes(routes, locationArg) {
|
|
|
468
435
|
// router loaded. We can help them understand how to avoid that.
|
|
469
436
|
"useRoutes() may be used only in the context of a <Router> component.") : invariant(false) : void 0;
|
|
470
437
|
let {
|
|
471
|
-
|
|
472
|
-
pathname: parentPathname,
|
|
473
|
-
pathnameBase: parentPathnameBase,
|
|
474
|
-
route: parentRoute
|
|
438
|
+
matches: parentMatches
|
|
475
439
|
} = useContext(RouteContext);
|
|
440
|
+
let routeMatch = parentMatches[parentMatches.length - 1];
|
|
441
|
+
let parentParams = routeMatch ? routeMatch.params : {};
|
|
442
|
+
let parentPathname = routeMatch ? routeMatch.pathname : "/";
|
|
443
|
+
let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
|
|
444
|
+
let parentRoute = routeMatch && routeMatch.route;
|
|
476
445
|
|
|
477
446
|
if (process.env.NODE_ENV !== "production") {
|
|
478
447
|
// You won't get a warning about 2 different <Routes> under a <Route>
|
|
@@ -520,13 +489,14 @@ function useRoutes(routes, locationArg) {
|
|
|
520
489
|
|
|
521
490
|
if (process.env.NODE_ENV !== "production") {
|
|
522
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;
|
|
523
493
|
}
|
|
524
494
|
|
|
525
|
-
return
|
|
495
|
+
return _renderMatches(matches && matches.map(match => Object.assign({}, match, {
|
|
526
496
|
params: Object.assign({}, parentParams, match.params),
|
|
527
497
|
pathname: joinPaths([parentPathnameBase, match.pathname]),
|
|
528
|
-
pathnameBase: joinPaths([parentPathnameBase, match.pathnameBase])
|
|
529
|
-
})));
|
|
498
|
+
pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([parentPathnameBase, match.pathnameBase])
|
|
499
|
+
})), parentMatches);
|
|
530
500
|
} ///////////////////////////////////////////////////////////////////////////////
|
|
531
501
|
// UTILS
|
|
532
502
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -536,7 +506,7 @@ function useRoutes(routes, locationArg) {
|
|
|
536
506
|
* either a `<Route>` element or an array of them. Used internally by
|
|
537
507
|
* `<Routes>` to create a route config from its children.
|
|
538
508
|
*
|
|
539
|
-
* @see https://reactrouter.com/api
|
|
509
|
+
* @see https://reactrouter.com/docs/en/v6/api#createroutesfromchildren
|
|
540
510
|
*/
|
|
541
511
|
|
|
542
512
|
function createRoutesFromChildren(children) {
|
|
@@ -554,6 +524,7 @@ function createRoutesFromChildren(children) {
|
|
|
554
524
|
return;
|
|
555
525
|
}
|
|
556
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;
|
|
557
528
|
let route = {
|
|
558
529
|
caseSensitive: element.props.caseSensitive,
|
|
559
530
|
element: element.props.element,
|
|
@@ -576,7 +547,7 @@ function createRoutesFromChildren(children) {
|
|
|
576
547
|
/**
|
|
577
548
|
* Returns a path with params interpolated.
|
|
578
549
|
*
|
|
579
|
-
* @see https://reactrouter.com/api
|
|
550
|
+
* @see https://reactrouter.com/docs/en/v6/api#generatepath
|
|
580
551
|
*/
|
|
581
552
|
function generatePath(path, params) {
|
|
582
553
|
if (params === void 0) {
|
|
@@ -595,7 +566,7 @@ function generatePath(path, params) {
|
|
|
595
566
|
/**
|
|
596
567
|
* Matches the given routes to a location and returns the match data.
|
|
597
568
|
*
|
|
598
|
-
* @see https://reactrouter.com/api
|
|
569
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchroutes
|
|
599
570
|
*/
|
|
600
571
|
function matchRoutes(routes, locationArg, basename) {
|
|
601
572
|
if (basename === void 0) {
|
|
@@ -663,7 +634,7 @@ function flattenRoutes(routes, branches, parentsMeta, parentPath) {
|
|
|
663
634
|
|
|
664
635
|
branches.push({
|
|
665
636
|
path,
|
|
666
|
-
score: computeScore(path),
|
|
637
|
+
score: computeScore(path, route.index),
|
|
667
638
|
routesMeta
|
|
668
639
|
});
|
|
669
640
|
});
|
|
@@ -676,14 +647,15 @@ function rankRouteBranches(branches) {
|
|
|
676
647
|
}
|
|
677
648
|
|
|
678
649
|
const paramRe = /^:\w+$/;
|
|
679
|
-
const dynamicSegmentValue =
|
|
650
|
+
const dynamicSegmentValue = 3;
|
|
651
|
+
const indexRouteValue = 2;
|
|
680
652
|
const emptySegmentValue = 1;
|
|
681
653
|
const staticSegmentValue = 10;
|
|
682
654
|
const splatPenalty = -2;
|
|
683
655
|
|
|
684
656
|
const isSplat = s => s === "*";
|
|
685
657
|
|
|
686
|
-
function computeScore(path) {
|
|
658
|
+
function computeScore(path, index) {
|
|
687
659
|
let segments = path.split("/");
|
|
688
660
|
let initialScore = segments.length;
|
|
689
661
|
|
|
@@ -691,6 +663,10 @@ function computeScore(path) {
|
|
|
691
663
|
initialScore += splatPenalty;
|
|
692
664
|
}
|
|
693
665
|
|
|
666
|
+
if (index) {
|
|
667
|
+
initialScore += indexRouteValue;
|
|
668
|
+
}
|
|
669
|
+
|
|
694
670
|
return segments.filter(s => !isSplat(s)).reduce((score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue), initialScore);
|
|
695
671
|
}
|
|
696
672
|
|
|
@@ -733,7 +709,11 @@ routesArg, pathname) {
|
|
|
733
709
|
pathnameBase: joinPaths([matchedPathname, match.pathnameBase]),
|
|
734
710
|
route
|
|
735
711
|
});
|
|
736
|
-
|
|
712
|
+
|
|
713
|
+
if (match.pathnameBase !== "/") {
|
|
714
|
+
matchedPathname = joinPaths([matchedPathname, match.pathnameBase]);
|
|
715
|
+
}
|
|
716
|
+
|
|
737
717
|
routes = route.children;
|
|
738
718
|
}
|
|
739
719
|
|
|
@@ -745,16 +725,21 @@ routesArg, pathname) {
|
|
|
745
725
|
|
|
746
726
|
|
|
747
727
|
function renderMatches(matches) {
|
|
728
|
+
return _renderMatches(matches);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function _renderMatches(matches, parentMatches) {
|
|
732
|
+
if (parentMatches === void 0) {
|
|
733
|
+
parentMatches = [];
|
|
734
|
+
}
|
|
735
|
+
|
|
748
736
|
if (matches == null) return null;
|
|
749
|
-
return matches.reduceRight((outlet, match) => {
|
|
737
|
+
return matches.reduceRight((outlet, match, index) => {
|
|
750
738
|
return /*#__PURE__*/createElement(RouteContext.Provider, {
|
|
751
|
-
children: match.route.element
|
|
739
|
+
children: match.route.element !== undefined ? match.route.element : /*#__PURE__*/createElement(Outlet, null),
|
|
752
740
|
value: {
|
|
753
741
|
outlet,
|
|
754
|
-
|
|
755
|
-
pathname: match.pathname,
|
|
756
|
-
pathnameBase: match.pathnameBase,
|
|
757
|
-
route: match.route
|
|
742
|
+
matches: parentMatches.concat(matches.slice(0, index + 1))
|
|
758
743
|
}
|
|
759
744
|
});
|
|
760
745
|
}, null);
|
|
@@ -763,11 +748,12 @@ function renderMatches(matches) {
|
|
|
763
748
|
* A PathPattern is used to match on some portion of a URL pathname.
|
|
764
749
|
*/
|
|
765
750
|
|
|
751
|
+
|
|
766
752
|
/**
|
|
767
753
|
* Performs pattern matching on a URL pathname and returns information about
|
|
768
754
|
* the match.
|
|
769
755
|
*
|
|
770
|
-
* @see https://reactrouter.com/api
|
|
756
|
+
* @see https://reactrouter.com/docs/en/v6/api#matchpath
|
|
771
757
|
*/
|
|
772
758
|
function matchPath(pattern, pathname) {
|
|
773
759
|
if (typeof pattern === "string") {
|
|
@@ -849,7 +835,7 @@ function safelyDecodeURIComponent(value, paramName) {
|
|
|
849
835
|
/**
|
|
850
836
|
* Returns a resolved path object relative to the given pathname.
|
|
851
837
|
*
|
|
852
|
-
* @see https://reactrouter.com/api
|
|
838
|
+
* @see https://reactrouter.com/docs/en/v6/api#resolvepath
|
|
853
839
|
*/
|
|
854
840
|
|
|
855
841
|
|
|
@@ -885,17 +871,48 @@ function resolvePathname(relativePath, fromPathname) {
|
|
|
885
871
|
return segments.length > 1 ? segments.join("/") : "/";
|
|
886
872
|
}
|
|
887
873
|
|
|
888
|
-
function resolveTo(
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
// `<Link to>` values` in our
|
|
892
|
-
// disambiguation between `to` values
|
|
893
|
-
// that do not. However, this is problematic for
|
|
894
|
-
// not provide a pathname. `to` can simply be a search or
|
|
895
|
-
// string, in which case we should assume that the navigation is
|
|
896
|
-
//
|
|
897
|
-
|
|
898
|
-
|
|
874
|
+
function resolveTo(toArg, routePathnames, locationPathname) {
|
|
875
|
+
let to = typeof toArg === "string" ? parsePath(toArg) : toArg;
|
|
876
|
+
let toPathname = toArg === "" || to.pathname === "" ? "/" : to.pathname; // If a pathname is explicitly provided in `to`, it should be relative to the
|
|
877
|
+
// route context. This is explained in `Note on `<Link to>` values` in our
|
|
878
|
+
// migration guide from v5 as a means of disambiguation between `to` values
|
|
879
|
+
// that begin with `/` and those that do not. However, this is problematic for
|
|
880
|
+
// `to` values that do not provide a pathname. `to` can simply be a search or
|
|
881
|
+
// hash string, in which case we should assume that the navigation is relative
|
|
882
|
+
// to the current location's pathname and *not* the route pathname.
|
|
883
|
+
|
|
884
|
+
let from;
|
|
885
|
+
|
|
886
|
+
if (toPathname == null) {
|
|
887
|
+
from = locationPathname;
|
|
888
|
+
} else {
|
|
889
|
+
let routePathnameIndex = routePathnames.length - 1;
|
|
890
|
+
|
|
891
|
+
if (toPathname.startsWith("..")) {
|
|
892
|
+
let toSegments = toPathname.split("/"); // Each leading .. segment means "go up one route" instead of "go up one
|
|
893
|
+
// URL segment". This is a key difference from how <a href> works and a
|
|
894
|
+
// major reason we call this a "to" value instead of a "href".
|
|
895
|
+
|
|
896
|
+
while (toSegments[0] === "..") {
|
|
897
|
+
toSegments.shift();
|
|
898
|
+
routePathnameIndex -= 1;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
to.pathname = toSegments.join("/");
|
|
902
|
+
} // If there are more ".." segments than parent routes, resolve relative to
|
|
903
|
+
// the root / URL.
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
let path = resolvePath(to, from); // Ensure the pathname has a trailing slash if the original to value had one.
|
|
910
|
+
|
|
911
|
+
if (toPathname && toPathname !== "/" && toPathname.endsWith("/") && !path.pathname.endsWith("/")) {
|
|
912
|
+
path.pathname += "/";
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
return path;
|
|
899
916
|
}
|
|
900
917
|
|
|
901
918
|
function getToPathname(to) {
|
|
@@ -928,5 +945,5 @@ const normalizeSearch = search => !search || search === "?" ? "" : search.starts
|
|
|
928
945
|
|
|
929
946
|
const normalizeHash = hash => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash; ///////////////////////////////////////////////////////////////////////////////
|
|
930
947
|
|
|
931
|
-
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,
|
|
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 };
|
|
932
949
|
//# sourceMappingURL=index.js.map
|