react-router 0.0.0-experimental-dc8656c8 → 0.0.0-experimental-5f08b33f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/index.js +114 -195
- package/dist/index.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/react-router.development.js +81 -205
- package/dist/react-router.development.js.map +1 -1
- package/dist/react-router.production.min.js +2 -2
- package/dist/react-router.production.min.js.map +1 -1
- package/dist/umd/react-router.development.js +114 -195
- package/dist/umd/react-router.development.js.map +1 -1
- package/dist/umd/react-router.production.min.js +2 -2
- package/dist/umd/react-router.production.min.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router v0.0.0-experimental-
|
|
2
|
+
* React Router v0.0.0-experimental-5f08b33f
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -16,61 +16,59 @@ function _extends() {
|
|
|
16
16
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
17
17
|
for (var i = 1; i < arguments.length; i++) {
|
|
18
18
|
var source = arguments[i];
|
|
19
|
-
|
|
20
19
|
for (var key in source) {
|
|
21
20
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
22
21
|
target[key] = source[key];
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
|
-
|
|
27
25
|
return target;
|
|
28
26
|
};
|
|
29
27
|
return _extends.apply(this, arguments);
|
|
30
28
|
}
|
|
31
29
|
|
|
30
|
+
// Create react-specific types from the agnostic types in @remix-run/router to
|
|
31
|
+
// export from react-router
|
|
32
32
|
const DataRouterContext = /*#__PURE__*/React.createContext(null);
|
|
33
|
-
|
|
34
33
|
if (process.env.NODE_ENV !== "production") {
|
|
35
34
|
DataRouterContext.displayName = "DataRouter";
|
|
36
35
|
}
|
|
37
|
-
|
|
38
36
|
const DataRouterStateContext = /*#__PURE__*/React.createContext(null);
|
|
39
|
-
|
|
40
37
|
if (process.env.NODE_ENV !== "production") {
|
|
41
38
|
DataRouterStateContext.displayName = "DataRouterState";
|
|
42
39
|
}
|
|
43
|
-
|
|
44
40
|
const AwaitContext = /*#__PURE__*/React.createContext(null);
|
|
45
|
-
|
|
46
41
|
if (process.env.NODE_ENV !== "production") {
|
|
47
42
|
AwaitContext.displayName = "Await";
|
|
48
43
|
}
|
|
49
44
|
|
|
50
|
-
|
|
45
|
+
/**
|
|
46
|
+
* A Navigator is a "location changer"; it's how you get to different locations.
|
|
47
|
+
*
|
|
48
|
+
* Every history instance conforms to the Navigator interface, but the
|
|
49
|
+
* distinction is useful primarily when it comes to the low-level <Router> API
|
|
50
|
+
* where both the location and a navigator must be provided separately in order
|
|
51
|
+
* to avoid "tearing" that may occur in a suspense-enabled app if the action
|
|
52
|
+
* and/or location were to be read directly from the history instance.
|
|
53
|
+
*/
|
|
51
54
|
|
|
55
|
+
const NavigationContext = /*#__PURE__*/React.createContext(null);
|
|
52
56
|
if (process.env.NODE_ENV !== "production") {
|
|
53
57
|
NavigationContext.displayName = "Navigation";
|
|
54
58
|
}
|
|
55
|
-
|
|
56
59
|
const LocationContext = /*#__PURE__*/React.createContext(null);
|
|
57
|
-
|
|
58
60
|
if (process.env.NODE_ENV !== "production") {
|
|
59
61
|
LocationContext.displayName = "Location";
|
|
60
62
|
}
|
|
61
|
-
|
|
62
63
|
const RouteContext = /*#__PURE__*/React.createContext({
|
|
63
64
|
outlet: null,
|
|
64
65
|
matches: [],
|
|
65
66
|
isDataRoute: false
|
|
66
67
|
});
|
|
67
|
-
|
|
68
68
|
if (process.env.NODE_ENV !== "production") {
|
|
69
69
|
RouteContext.displayName = "Route";
|
|
70
70
|
}
|
|
71
|
-
|
|
72
71
|
const RouteErrorContext = /*#__PURE__*/React.createContext(null);
|
|
73
|
-
|
|
74
72
|
if (process.env.NODE_ENV !== "production") {
|
|
75
73
|
RouteErrorContext.displayName = "RouteError";
|
|
76
74
|
}
|
|
@@ -81,7 +79,6 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
81
79
|
*
|
|
82
80
|
* @see https://reactrouter.com/hooks/use-href
|
|
83
81
|
*/
|
|
84
|
-
|
|
85
82
|
function useHref(to, _temp) {
|
|
86
83
|
let {
|
|
87
84
|
relative
|
|
@@ -100,30 +97,31 @@ function useHref(to, _temp) {
|
|
|
100
97
|
} = useResolvedPath(to, {
|
|
101
98
|
relative
|
|
102
99
|
});
|
|
103
|
-
let joinedPathname = pathname;
|
|
100
|
+
let joinedPathname = pathname;
|
|
101
|
+
|
|
102
|
+
// If we're operating within a basename, prepend it to the pathname prior
|
|
104
103
|
// to creating the href. If this is a root navigation, then just use the raw
|
|
105
104
|
// basename which allows the basename to have full control over the presence
|
|
106
105
|
// of a trailing slash on root links
|
|
107
|
-
|
|
108
106
|
if (basename !== "/") {
|
|
109
107
|
joinedPathname = pathname === "/" ? basename : joinPaths([basename, pathname]);
|
|
110
108
|
}
|
|
111
|
-
|
|
112
109
|
return navigator.createHref({
|
|
113
110
|
pathname: joinedPathname,
|
|
114
111
|
search,
|
|
115
112
|
hash
|
|
116
113
|
});
|
|
117
114
|
}
|
|
115
|
+
|
|
118
116
|
/**
|
|
119
117
|
* Returns true if this component is a descendant of a <Router>.
|
|
120
118
|
*
|
|
121
119
|
* @see https://reactrouter.com/hooks/use-in-router-context
|
|
122
120
|
*/
|
|
123
|
-
|
|
124
121
|
function useInRouterContext() {
|
|
125
122
|
return React.useContext(LocationContext) != null;
|
|
126
123
|
}
|
|
124
|
+
|
|
127
125
|
/**
|
|
128
126
|
* Returns the current location object, which represents the current URL in web
|
|
129
127
|
* browsers.
|
|
@@ -134,23 +132,23 @@ function useInRouterContext() {
|
|
|
134
132
|
*
|
|
135
133
|
* @see https://reactrouter.com/hooks/use-location
|
|
136
134
|
*/
|
|
137
|
-
|
|
138
135
|
function useLocation() {
|
|
139
136
|
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
140
137
|
// router loaded. We can help them understand how to avoid that.
|
|
141
138
|
"useLocation() may be used only in the context of a <Router> component.") : UNSAFE_invariant(false) : void 0;
|
|
142
139
|
return React.useContext(LocationContext).location;
|
|
143
140
|
}
|
|
141
|
+
|
|
144
142
|
/**
|
|
145
143
|
* Returns the current navigation action which describes how the router came to
|
|
146
144
|
* the current location, either by a pop, push, or replace on the history stack.
|
|
147
145
|
*
|
|
148
146
|
* @see https://reactrouter.com/hooks/use-navigation-type
|
|
149
147
|
*/
|
|
150
|
-
|
|
151
148
|
function useNavigationType() {
|
|
152
149
|
return React.useContext(LocationContext).navigationType;
|
|
153
150
|
}
|
|
151
|
+
|
|
154
152
|
/**
|
|
155
153
|
* Returns a PathMatch object if the given pattern matches the current URL.
|
|
156
154
|
* This is useful for components that need to know "active" state, e.g.
|
|
@@ -158,7 +156,6 @@ function useNavigationType() {
|
|
|
158
156
|
*
|
|
159
157
|
* @see https://reactrouter.com/hooks/use-match
|
|
160
158
|
*/
|
|
161
|
-
|
|
162
159
|
function useMatch(pattern) {
|
|
163
160
|
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
164
161
|
// router loaded. We can help them understand how to avoid that.
|
|
@@ -168,15 +165,16 @@ function useMatch(pattern) {
|
|
|
168
165
|
} = useLocation();
|
|
169
166
|
return React.useMemo(() => matchPath(pattern, pathname), [pathname, pattern]);
|
|
170
167
|
}
|
|
168
|
+
|
|
171
169
|
/**
|
|
172
170
|
* The interface for the navigate() function returned from useNavigate().
|
|
173
171
|
*/
|
|
174
172
|
|
|
175
|
-
const navigateEffectWarning = "You should call navigate() in a React.useEffect(), not when " + "your component is first rendered.";
|
|
173
|
+
const navigateEffectWarning = "You should call navigate() in a React.useEffect(), not when " + "your component is first rendered.";
|
|
176
174
|
|
|
175
|
+
// Mute warnings for calls to useNavigate in SSR environments
|
|
177
176
|
function useIsomorphicLayoutEffect(cb) {
|
|
178
177
|
let isStatic = React.useContext(NavigationContext).static;
|
|
179
|
-
|
|
180
178
|
if (!isStatic) {
|
|
181
179
|
// We should be able to get rid of this once react 18.3 is released
|
|
182
180
|
// See: https://github.com/facebook/react/pull/26395
|
|
@@ -184,23 +182,21 @@ function useIsomorphicLayoutEffect(cb) {
|
|
|
184
182
|
React.useLayoutEffect(cb);
|
|
185
183
|
}
|
|
186
184
|
}
|
|
185
|
+
|
|
187
186
|
/**
|
|
188
187
|
* Returns an imperative method for changing the location. Used by <Link>s, but
|
|
189
188
|
* may also be used by other elements to change the location.
|
|
190
189
|
*
|
|
191
190
|
* @see https://reactrouter.com/hooks/use-navigate
|
|
192
191
|
*/
|
|
193
|
-
|
|
194
|
-
|
|
195
192
|
function useNavigate() {
|
|
196
193
|
let {
|
|
197
194
|
isDataRoute
|
|
198
|
-
} = React.useContext(RouteContext);
|
|
195
|
+
} = React.useContext(RouteContext);
|
|
196
|
+
// Conditional usage is OK here because the usage of a data router is static
|
|
199
197
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
200
|
-
|
|
201
198
|
return isDataRoute ? useNavigateStable() : useNavigateUnstable();
|
|
202
199
|
}
|
|
203
|
-
|
|
204
200
|
function useNavigateUnstable() {
|
|
205
201
|
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
206
202
|
// router loaded. We can help them understand how to avoid that.
|
|
@@ -225,68 +221,63 @@ function useNavigateUnstable() {
|
|
|
225
221
|
if (options === void 0) {
|
|
226
222
|
options = {};
|
|
227
223
|
}
|
|
224
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(activeRef.current, navigateEffectWarning) : void 0;
|
|
228
225
|
|
|
229
|
-
|
|
226
|
+
// Short circuit here since if this happens on first render the navigate
|
|
230
227
|
// is useless because we haven't wired up our history listener yet
|
|
231
|
-
|
|
232
228
|
if (!activeRef.current) return;
|
|
233
|
-
|
|
234
229
|
if (typeof to === "number") {
|
|
235
230
|
navigator.go(to);
|
|
236
231
|
return;
|
|
237
232
|
}
|
|
233
|
+
let path = resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, options.relative === "path");
|
|
238
234
|
|
|
239
|
-
|
|
235
|
+
// If we're operating within a basename, prepend it to the pathname prior
|
|
240
236
|
// to handing off to history (but only if we're not in a data router,
|
|
241
237
|
// otherwise it'll prepend the basename inside of the router).
|
|
242
238
|
// If this is a root navigation, then we navigate to the raw basename
|
|
243
239
|
// which allows the basename to have full control over the presence of a
|
|
244
240
|
// trailing slash on root links
|
|
245
|
-
|
|
246
241
|
if (dataRouterContext == null && basename !== "/") {
|
|
247
242
|
path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
|
|
248
243
|
}
|
|
249
|
-
|
|
250
244
|
(!!options.replace ? navigator.replace : navigator.push)(path, options.state, options);
|
|
251
245
|
}, [basename, navigator, routePathnamesJson, locationPathname, dataRouterContext]);
|
|
252
246
|
return navigate;
|
|
253
247
|
}
|
|
254
|
-
|
|
255
248
|
const OutletContext = /*#__PURE__*/React.createContext(null);
|
|
249
|
+
|
|
256
250
|
/**
|
|
257
251
|
* Returns the context (if provided) for the child route at this level of the route
|
|
258
252
|
* hierarchy.
|
|
259
253
|
* @see https://reactrouter.com/hooks/use-outlet-context
|
|
260
254
|
*/
|
|
261
|
-
|
|
262
255
|
function useOutletContext() {
|
|
263
256
|
return React.useContext(OutletContext);
|
|
264
257
|
}
|
|
258
|
+
|
|
265
259
|
/**
|
|
266
260
|
* Returns the element for the child route at this level of the route
|
|
267
261
|
* hierarchy. Used internally by <Outlet> to render child routes.
|
|
268
262
|
*
|
|
269
263
|
* @see https://reactrouter.com/hooks/use-outlet
|
|
270
264
|
*/
|
|
271
|
-
|
|
272
265
|
function useOutlet(context) {
|
|
273
266
|
let outlet = React.useContext(RouteContext).outlet;
|
|
274
|
-
|
|
275
267
|
if (outlet) {
|
|
276
268
|
return /*#__PURE__*/React.createElement(OutletContext.Provider, {
|
|
277
269
|
value: context
|
|
278
270
|
}, outlet);
|
|
279
271
|
}
|
|
280
|
-
|
|
281
272
|
return outlet;
|
|
282
273
|
}
|
|
274
|
+
|
|
283
275
|
/**
|
|
284
276
|
* Returns an object of key/value pairs of the dynamic params from the current
|
|
285
277
|
* URL that were matched by the route path.
|
|
286
278
|
*
|
|
287
279
|
* @see https://reactrouter.com/hooks/use-params
|
|
288
280
|
*/
|
|
289
|
-
|
|
290
281
|
function useParams() {
|
|
291
282
|
let {
|
|
292
283
|
matches
|
|
@@ -294,12 +285,12 @@ function useParams() {
|
|
|
294
285
|
let routeMatch = matches[matches.length - 1];
|
|
295
286
|
return routeMatch ? routeMatch.params : {};
|
|
296
287
|
}
|
|
288
|
+
|
|
297
289
|
/**
|
|
298
290
|
* Resolves the pathname of the given `to` value against the current location.
|
|
299
291
|
*
|
|
300
292
|
* @see https://reactrouter.com/hooks/use-resolved-path
|
|
301
293
|
*/
|
|
302
|
-
|
|
303
294
|
function useResolvedPath(to, _temp2) {
|
|
304
295
|
let {
|
|
305
296
|
relative
|
|
@@ -313,6 +304,7 @@ function useResolvedPath(to, _temp2) {
|
|
|
313
304
|
let routePathnamesJson = JSON.stringify(UNSAFE_getPathContributingMatches(matches).map(match => match.pathnameBase));
|
|
314
305
|
return React.useMemo(() => resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, relative === "path"), [to, routePathnamesJson, locationPathname, relative]);
|
|
315
306
|
}
|
|
307
|
+
|
|
316
308
|
/**
|
|
317
309
|
* Returns the element of the route that matched the current location, prepared
|
|
318
310
|
* with the correct context to render the remainder of the route tree. Route
|
|
@@ -321,11 +313,11 @@ function useResolvedPath(to, _temp2) {
|
|
|
321
313
|
*
|
|
322
314
|
* @see https://reactrouter.com/hooks/use-routes
|
|
323
315
|
*/
|
|
324
|
-
|
|
325
316
|
function useRoutes(routes, locationArg) {
|
|
326
317
|
return useRoutesImpl(routes, locationArg);
|
|
327
|
-
}
|
|
318
|
+
}
|
|
328
319
|
|
|
320
|
+
// Internal implementation with accept optional param for RouterProvider usage
|
|
329
321
|
function useRoutesImpl(routes, locationArg, dataRouterState) {
|
|
330
322
|
!useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, // TODO: This error is probably because they somehow have 2 versions of the
|
|
331
323
|
// router loaded. We can help them understand how to avoid that.
|
|
@@ -341,7 +333,6 @@ function useRoutesImpl(routes, locationArg, dataRouterState) {
|
|
|
341
333
|
let parentPathname = routeMatch ? routeMatch.pathname : "/";
|
|
342
334
|
let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
|
|
343
335
|
let parentRoute = routeMatch && routeMatch.route;
|
|
344
|
-
|
|
345
336
|
if (process.env.NODE_ENV !== "production") {
|
|
346
337
|
// You won't get a warning about 2 different <Routes> under a <Route>
|
|
347
338
|
// without a trailing *, but this is a best-effort warning anyway since we
|
|
@@ -366,42 +357,38 @@ function useRoutesImpl(routes, locationArg, dataRouterState) {
|
|
|
366
357
|
let parentPath = parentRoute && parentRoute.path || "";
|
|
367
358
|
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 + "/*") + "\">."));
|
|
368
359
|
}
|
|
369
|
-
|
|
370
360
|
let locationFromContext = useLocation();
|
|
371
361
|
let location;
|
|
372
|
-
|
|
373
362
|
if (locationArg) {
|
|
374
363
|
var _parsedLocationArg$pa;
|
|
375
|
-
|
|
376
364
|
let parsedLocationArg = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
|
377
365
|
!(parentPathnameBase === "/" || ((_parsedLocationArg$pa = parsedLocationArg.pathname) == null ? void 0 : _parsedLocationArg$pa.startsWith(parentPathnameBase))) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "When overriding the location using `<Routes location>` or `useRoutes(routes, location)`, " + "the location pathname must begin with the portion of the URL pathname that was " + ("matched by all parent routes. The current pathname base is \"" + parentPathnameBase + "\" ") + ("but pathname \"" + parsedLocationArg.pathname + "\" was given in the `location` prop.")) : UNSAFE_invariant(false) : void 0;
|
|
378
366
|
location = parsedLocationArg;
|
|
379
367
|
} else {
|
|
380
368
|
location = locationFromContext;
|
|
381
369
|
}
|
|
382
|
-
|
|
383
370
|
let pathname = location.pathname || "/";
|
|
384
371
|
let remainingPathname = parentPathnameBase === "/" ? pathname : pathname.slice(parentPathnameBase.length) || "/";
|
|
385
372
|
let matches = matchRoutes(routes, {
|
|
386
373
|
pathname: remainingPathname
|
|
387
374
|
});
|
|
388
|
-
|
|
389
375
|
if (process.env.NODE_ENV !== "production") {
|
|
390
376
|
process.env.NODE_ENV !== "production" ? UNSAFE_warning(parentRoute || matches != null, "No routes matched location \"" + location.pathname + location.search + location.hash + "\" ") : void 0;
|
|
391
377
|
process.env.NODE_ENV !== "production" ? UNSAFE_warning(matches == null || matches[matches.length - 1].route.element !== undefined || matches[matches.length - 1].route.Component !== undefined, "Matched leaf route at location \"" + location.pathname + location.search + location.hash + "\" " + "does not have an element or Component. This means it will render an <Outlet /> with a " + "null value by default resulting in an \"empty\" page.") : void 0;
|
|
392
378
|
}
|
|
393
|
-
|
|
394
379
|
let renderedMatches = _renderMatches(matches && matches.map(match => Object.assign({}, match, {
|
|
395
380
|
params: Object.assign({}, parentParams, match.params),
|
|
396
|
-
pathname: joinPaths([parentPathnameBase,
|
|
381
|
+
pathname: joinPaths([parentPathnameBase,
|
|
382
|
+
// Re-encode pathnames that were decoded inside matchRoutes
|
|
397
383
|
navigator.encodeLocation ? navigator.encodeLocation(match.pathname).pathname : match.pathname]),
|
|
398
|
-
pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([parentPathnameBase,
|
|
384
|
+
pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([parentPathnameBase,
|
|
385
|
+
// Re-encode pathnames that were decoded inside matchRoutes
|
|
399
386
|
navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase).pathname : match.pathnameBase])
|
|
400
|
-
})), parentMatches, dataRouterState);
|
|
387
|
+
})), parentMatches, dataRouterState);
|
|
388
|
+
|
|
389
|
+
// When a user passes in a `locationArg`, the associated routes need to
|
|
401
390
|
// be wrapped in a new `LocationContext.Provider` in order for `useLocation`
|
|
402
391
|
// to use the scoped location instead of the global location.
|
|
403
|
-
|
|
404
|
-
|
|
405
392
|
if (locationArg && renderedMatches) {
|
|
406
393
|
return /*#__PURE__*/React.createElement(LocationContext.Provider, {
|
|
407
394
|
value: {
|
|
@@ -416,10 +403,8 @@ function useRoutesImpl(routes, locationArg, dataRouterState) {
|
|
|
416
403
|
}
|
|
417
404
|
}, renderedMatches);
|
|
418
405
|
}
|
|
419
|
-
|
|
420
406
|
return renderedMatches;
|
|
421
407
|
}
|
|
422
|
-
|
|
423
408
|
function DefaultErrorComponent() {
|
|
424
409
|
let error = useRouteError();
|
|
425
410
|
let message = isRouteErrorResponse(error) ? error.status + " " + error.statusText : error instanceof Error ? error.message : JSON.stringify(error);
|
|
@@ -434,7 +419,6 @@ function DefaultErrorComponent() {
|
|
|
434
419
|
backgroundColor: lightgrey
|
|
435
420
|
};
|
|
436
421
|
let devInfo = null;
|
|
437
|
-
|
|
438
422
|
if (process.env.NODE_ENV !== "production") {
|
|
439
423
|
console.error("Error handled by React Router default ErrorBoundary:", error);
|
|
440
424
|
devInfo = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("p", null, "\uD83D\uDCBF Hey developer \uD83D\uDC4B"), /*#__PURE__*/React.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /*#__PURE__*/React.createElement("code", {
|
|
@@ -443,7 +427,6 @@ function DefaultErrorComponent() {
|
|
|
443
427
|
style: codeStyles
|
|
444
428
|
}, "errorElement"), " prop on your route."));
|
|
445
429
|
}
|
|
446
|
-
|
|
447
430
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("h2", null, "Unexpected Application Error!"), /*#__PURE__*/React.createElement("h3", {
|
|
448
431
|
style: {
|
|
449
432
|
fontStyle: "italic"
|
|
@@ -452,7 +435,6 @@ function DefaultErrorComponent() {
|
|
|
452
435
|
style: preStyles
|
|
453
436
|
}, stack) : null, devInfo);
|
|
454
437
|
}
|
|
455
|
-
|
|
456
438
|
const defaultErrorElement = /*#__PURE__*/React.createElement(DefaultErrorComponent, null);
|
|
457
439
|
class RenderErrorBoundary extends React.Component {
|
|
458
440
|
constructor(props) {
|
|
@@ -463,13 +445,11 @@ class RenderErrorBoundary extends React.Component {
|
|
|
463
445
|
error: props.error
|
|
464
446
|
};
|
|
465
447
|
}
|
|
466
|
-
|
|
467
448
|
static getDerivedStateFromError(error) {
|
|
468
449
|
return {
|
|
469
450
|
error: error
|
|
470
451
|
};
|
|
471
452
|
}
|
|
472
|
-
|
|
473
453
|
static getDerivedStateFromProps(props, state) {
|
|
474
454
|
// When we get into an error state, the user will likely click "back" to the
|
|
475
455
|
// previous page that didn't have an error. Because this wraps the entire
|
|
@@ -485,23 +465,21 @@ class RenderErrorBoundary extends React.Component {
|
|
|
485
465
|
location: props.location,
|
|
486
466
|
revalidation: props.revalidation
|
|
487
467
|
};
|
|
488
|
-
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// If we're not changing locations, preserve the location but still surface
|
|
489
471
|
// any new errors that may come through. We retain the existing error, we do
|
|
490
472
|
// this because the error provided from the app state may be cleared without
|
|
491
473
|
// the location changing.
|
|
492
|
-
|
|
493
|
-
|
|
494
474
|
return {
|
|
495
475
|
error: props.error || state.error,
|
|
496
476
|
location: state.location,
|
|
497
477
|
revalidation: props.revalidation || state.revalidation
|
|
498
478
|
};
|
|
499
479
|
}
|
|
500
|
-
|
|
501
480
|
componentDidCatch(error, errorInfo) {
|
|
502
481
|
console.error("React Router caught the following error during render", error, errorInfo);
|
|
503
482
|
}
|
|
504
|
-
|
|
505
483
|
render() {
|
|
506
484
|
return this.state.error ? /*#__PURE__*/React.createElement(RouteContext.Provider, {
|
|
507
485
|
value: this.props.routeContext
|
|
@@ -510,41 +488,34 @@ class RenderErrorBoundary extends React.Component {
|
|
|
510
488
|
children: this.props.component
|
|
511
489
|
})) : this.props.children;
|
|
512
490
|
}
|
|
513
|
-
|
|
514
491
|
}
|
|
515
|
-
|
|
516
492
|
function RenderedRoute(_ref) {
|
|
517
493
|
let {
|
|
518
494
|
routeContext,
|
|
519
495
|
match,
|
|
520
496
|
children
|
|
521
497
|
} = _ref;
|
|
522
|
-
let dataRouterContext = React.useContext(DataRouterContext);
|
|
523
|
-
// in a DataStaticRouter
|
|
498
|
+
let dataRouterContext = React.useContext(DataRouterContext);
|
|
524
499
|
|
|
500
|
+
// Track how deep we got in our render pass to emulate SSR componentDidCatch
|
|
501
|
+
// in a DataStaticRouter
|
|
525
502
|
if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) {
|
|
526
503
|
dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
|
|
527
504
|
}
|
|
528
|
-
|
|
529
505
|
return /*#__PURE__*/React.createElement(RouteContext.Provider, {
|
|
530
506
|
value: routeContext
|
|
531
507
|
}, children);
|
|
532
508
|
}
|
|
533
|
-
|
|
534
509
|
function _renderMatches(matches, parentMatches, dataRouterState) {
|
|
535
510
|
var _dataRouterState2;
|
|
536
|
-
|
|
537
511
|
if (parentMatches === void 0) {
|
|
538
512
|
parentMatches = [];
|
|
539
513
|
}
|
|
540
|
-
|
|
541
514
|
if (dataRouterState === void 0) {
|
|
542
515
|
dataRouterState = null;
|
|
543
516
|
}
|
|
544
|
-
|
|
545
517
|
if (matches == null) {
|
|
546
518
|
var _dataRouterState;
|
|
547
|
-
|
|
548
519
|
if ((_dataRouterState = dataRouterState) != null && _dataRouterState.errors) {
|
|
549
520
|
// Don't bail if we have data router errors so we can render them in the
|
|
550
521
|
// boundary. Use the pre-matched (or shimmed) matches
|
|
@@ -553,31 +524,25 @@ function _renderMatches(matches, parentMatches, dataRouterState) {
|
|
|
553
524
|
return null;
|
|
554
525
|
}
|
|
555
526
|
}
|
|
527
|
+
let renderedMatches = matches;
|
|
556
528
|
|
|
557
|
-
|
|
558
|
-
|
|
529
|
+
// If we have data errors, trim matches to the highest error boundary
|
|
559
530
|
let errors = (_dataRouterState2 = dataRouterState) == null ? void 0 : _dataRouterState2.errors;
|
|
560
|
-
|
|
561
531
|
if (errors != null) {
|
|
562
532
|
let errorIndex = renderedMatches.findIndex(m => m.route.id && (errors == null ? void 0 : errors[m.route.id]));
|
|
563
533
|
!(errorIndex >= 0) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "Could not find a matching route for errors on route IDs: " + Object.keys(errors).join(",")) : UNSAFE_invariant(false) : void 0;
|
|
564
534
|
renderedMatches = renderedMatches.slice(0, Math.min(renderedMatches.length, errorIndex + 1));
|
|
565
535
|
}
|
|
566
|
-
|
|
567
536
|
return renderedMatches.reduceRight((outlet, match, index) => {
|
|
568
|
-
let error = match.route.id ? errors == null ? void 0 : errors[match.route.id] : null;
|
|
569
|
-
|
|
537
|
+
let error = match.route.id ? errors == null ? void 0 : errors[match.route.id] : null;
|
|
538
|
+
// Only data routers handle errors
|
|
570
539
|
let errorElement = null;
|
|
571
|
-
|
|
572
540
|
if (dataRouterState) {
|
|
573
541
|
errorElement = match.route.errorElement || defaultErrorElement;
|
|
574
542
|
}
|
|
575
|
-
|
|
576
543
|
let matches = parentMatches.concat(renderedMatches.slice(0, index + 1));
|
|
577
|
-
|
|
578
544
|
let getChildren = () => {
|
|
579
545
|
let children;
|
|
580
|
-
|
|
581
546
|
if (error) {
|
|
582
547
|
children = errorElement;
|
|
583
548
|
} else if (match.route.Component) {
|
|
@@ -593,7 +558,6 @@ function _renderMatches(matches, parentMatches, dataRouterState) {
|
|
|
593
558
|
} else {
|
|
594
559
|
children = outlet;
|
|
595
560
|
}
|
|
596
|
-
|
|
597
561
|
return /*#__PURE__*/React.createElement(RenderedRoute, {
|
|
598
562
|
match: match,
|
|
599
563
|
routeContext: {
|
|
@@ -603,11 +567,10 @@ function _renderMatches(matches, parentMatches, dataRouterState) {
|
|
|
603
567
|
},
|
|
604
568
|
children: children
|
|
605
569
|
});
|
|
606
|
-
};
|
|
570
|
+
};
|
|
571
|
+
// Only wrap in an error boundary within data router usages when we have an
|
|
607
572
|
// ErrorBoundary/errorElement on this route. Otherwise let it bubble up to
|
|
608
573
|
// an ancestor ErrorBoundary/errorElement
|
|
609
|
-
|
|
610
|
-
|
|
611
574
|
return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? /*#__PURE__*/React.createElement(RenderErrorBoundary, {
|
|
612
575
|
location: dataRouterState.location,
|
|
613
576
|
revalidation: dataRouterState.revalidation,
|
|
@@ -623,15 +586,12 @@ function _renderMatches(matches, parentMatches, dataRouterState) {
|
|
|
623
586
|
}, null);
|
|
624
587
|
}
|
|
625
588
|
var DataRouterHook;
|
|
626
|
-
|
|
627
589
|
(function (DataRouterHook) {
|
|
628
590
|
DataRouterHook["UseBlocker"] = "useBlocker";
|
|
629
591
|
DataRouterHook["UseRevalidator"] = "useRevalidator";
|
|
630
592
|
DataRouterHook["UseNavigateStable"] = "useNavigate";
|
|
631
593
|
})(DataRouterHook || (DataRouterHook = {}));
|
|
632
|
-
|
|
633
594
|
var DataRouterStateHook;
|
|
634
|
-
|
|
635
595
|
(function (DataRouterStateHook) {
|
|
636
596
|
DataRouterStateHook["UseBlocker"] = "useBlocker";
|
|
637
597
|
DataRouterStateHook["UseLoaderData"] = "useLoaderData";
|
|
@@ -644,58 +604,53 @@ var DataRouterStateHook;
|
|
|
644
604
|
DataRouterStateHook["UseNavigateStable"] = "useNavigate";
|
|
645
605
|
DataRouterStateHook["UseRouteId"] = "useRouteId";
|
|
646
606
|
})(DataRouterStateHook || (DataRouterStateHook = {}));
|
|
647
|
-
|
|
648
607
|
function getDataRouterConsoleError(hookName) {
|
|
649
608
|
return hookName + " must be used within a data router. See https://reactrouter.com/routers/picking-a-router.";
|
|
650
609
|
}
|
|
651
|
-
|
|
652
610
|
function useDataRouterContext(hookName) {
|
|
653
611
|
let ctx = React.useContext(DataRouterContext);
|
|
654
612
|
!ctx ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : UNSAFE_invariant(false) : void 0;
|
|
655
613
|
return ctx;
|
|
656
614
|
}
|
|
657
|
-
|
|
658
615
|
function useDataRouterState(hookName) {
|
|
659
616
|
let state = React.useContext(DataRouterStateContext);
|
|
660
617
|
!state ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : UNSAFE_invariant(false) : void 0;
|
|
661
618
|
return state;
|
|
662
619
|
}
|
|
663
|
-
|
|
664
620
|
function useRouteContext(hookName) {
|
|
665
621
|
let route = React.useContext(RouteContext);
|
|
666
622
|
!route ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : UNSAFE_invariant(false) : void 0;
|
|
667
623
|
return route;
|
|
668
|
-
}
|
|
669
|
-
|
|
624
|
+
}
|
|
670
625
|
|
|
626
|
+
// Internal version with hookName-aware debugging
|
|
671
627
|
function useCurrentRouteId(hookName) {
|
|
672
628
|
let route = useRouteContext(hookName);
|
|
673
629
|
let thisRoute = route.matches[route.matches.length - 1];
|
|
674
630
|
!thisRoute.route.id ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, hookName + " can only be used on routes that contain a unique \"id\"") : UNSAFE_invariant(false) : void 0;
|
|
675
631
|
return thisRoute.route.id;
|
|
676
632
|
}
|
|
633
|
+
|
|
677
634
|
/**
|
|
678
635
|
* Returns the ID for the nearest contextual route
|
|
679
636
|
*/
|
|
680
|
-
|
|
681
|
-
|
|
682
637
|
function useRouteId() {
|
|
683
638
|
return useCurrentRouteId(DataRouterStateHook.UseRouteId);
|
|
684
639
|
}
|
|
640
|
+
|
|
685
641
|
/**
|
|
686
642
|
* Returns the current navigation, defaulting to an "idle" navigation when
|
|
687
643
|
* no navigation is in progress
|
|
688
644
|
*/
|
|
689
|
-
|
|
690
645
|
function useNavigation() {
|
|
691
646
|
let state = useDataRouterState(DataRouterStateHook.UseNavigation);
|
|
692
647
|
return state.navigation;
|
|
693
648
|
}
|
|
649
|
+
|
|
694
650
|
/**
|
|
695
651
|
* Returns a revalidate function for manually triggering revalidation, as well
|
|
696
652
|
* as the current state of any manual revalidations
|
|
697
653
|
*/
|
|
698
|
-
|
|
699
654
|
function useRevalidator() {
|
|
700
655
|
let dataRouterContext = useDataRouterContext(DataRouterHook.UseRevalidator);
|
|
701
656
|
let state = useDataRouterState(DataRouterStateHook.UseRevalidator);
|
|
@@ -704,11 +659,11 @@ function useRevalidator() {
|
|
|
704
659
|
state: state.revalidation
|
|
705
660
|
};
|
|
706
661
|
}
|
|
662
|
+
|
|
707
663
|
/**
|
|
708
664
|
* Returns the active route matches, useful for accessing loaderData for
|
|
709
665
|
* parent/child routes or the route "handle" property
|
|
710
666
|
*/
|
|
711
|
-
|
|
712
667
|
function useMatches() {
|
|
713
668
|
let {
|
|
714
669
|
matches,
|
|
@@ -718,10 +673,10 @@ function useMatches() {
|
|
|
718
673
|
let {
|
|
719
674
|
pathname,
|
|
720
675
|
params
|
|
721
|
-
} = match;
|
|
676
|
+
} = match;
|
|
677
|
+
// Note: This structure matches that created by createUseMatchesMatch
|
|
722
678
|
// in the @remix-run/router , so if you change this please also change
|
|
723
679
|
// that :) Eventually we'll DRY this up
|
|
724
|
-
|
|
725
680
|
return {
|
|
726
681
|
id: match.route.id,
|
|
727
682
|
pathname,
|
|
@@ -731,84 +686,82 @@ function useMatches() {
|
|
|
731
686
|
};
|
|
732
687
|
}), [matches, loaderData]);
|
|
733
688
|
}
|
|
689
|
+
|
|
734
690
|
/**
|
|
735
691
|
* Returns the loader data for the nearest ancestor Route loader
|
|
736
692
|
*/
|
|
737
|
-
|
|
738
693
|
function useLoaderData() {
|
|
739
694
|
let state = useDataRouterState(DataRouterStateHook.UseLoaderData);
|
|
740
695
|
let routeId = useCurrentRouteId(DataRouterStateHook.UseLoaderData);
|
|
741
|
-
|
|
742
696
|
if (state.errors && state.errors[routeId] != null) {
|
|
743
697
|
console.error("You cannot `useLoaderData` in an errorElement (routeId: " + routeId + ")");
|
|
744
698
|
return undefined;
|
|
745
699
|
}
|
|
746
|
-
|
|
747
700
|
return state.loaderData[routeId];
|
|
748
701
|
}
|
|
702
|
+
|
|
749
703
|
/**
|
|
750
704
|
* Returns the loaderData for the given routeId
|
|
751
705
|
*/
|
|
752
|
-
|
|
753
706
|
function useRouteLoaderData(routeId) {
|
|
754
707
|
let state = useDataRouterState(DataRouterStateHook.UseRouteLoaderData);
|
|
755
708
|
return state.loaderData[routeId];
|
|
756
709
|
}
|
|
710
|
+
|
|
757
711
|
/**
|
|
758
712
|
* Returns the action data for the nearest ancestor Route action
|
|
759
713
|
*/
|
|
760
|
-
|
|
761
714
|
function useActionData() {
|
|
762
715
|
let state = useDataRouterState(DataRouterStateHook.UseActionData);
|
|
763
716
|
let route = React.useContext(RouteContext);
|
|
764
717
|
!route ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "useActionData must be used inside a RouteContext") : UNSAFE_invariant(false) : void 0;
|
|
765
718
|
return Object.values((state == null ? void 0 : state.actionData) || {})[0];
|
|
766
719
|
}
|
|
720
|
+
|
|
767
721
|
/**
|
|
768
722
|
* Returns the nearest ancestor Route error, which could be a loader/action
|
|
769
723
|
* error or a render error. This is intended to be called from your
|
|
770
724
|
* ErrorBoundary/errorElement to display a proper error message.
|
|
771
725
|
*/
|
|
772
|
-
|
|
773
726
|
function useRouteError() {
|
|
774
727
|
var _state$errors;
|
|
775
|
-
|
|
776
728
|
let error = React.useContext(RouteErrorContext);
|
|
777
729
|
let state = useDataRouterState(DataRouterStateHook.UseRouteError);
|
|
778
|
-
let routeId = useCurrentRouteId(DataRouterStateHook.UseRouteError);
|
|
779
|
-
// of RenderErrorBoundary
|
|
730
|
+
let routeId = useCurrentRouteId(DataRouterStateHook.UseRouteError);
|
|
780
731
|
|
|
732
|
+
// If this was a render error, we put it in a RouteError context inside
|
|
733
|
+
// of RenderErrorBoundary
|
|
781
734
|
if (error) {
|
|
782
735
|
return error;
|
|
783
|
-
}
|
|
784
|
-
|
|
736
|
+
}
|
|
785
737
|
|
|
738
|
+
// Otherwise look for errors from our data router state
|
|
786
739
|
return (_state$errors = state.errors) == null ? void 0 : _state$errors[routeId];
|
|
787
740
|
}
|
|
741
|
+
|
|
788
742
|
/**
|
|
789
743
|
* Returns the happy-path data from the nearest ancestor <Await /> value
|
|
790
744
|
*/
|
|
791
|
-
|
|
792
745
|
function useAsyncValue() {
|
|
793
746
|
let value = React.useContext(AwaitContext);
|
|
794
747
|
return value == null ? void 0 : value._data;
|
|
795
748
|
}
|
|
749
|
+
|
|
796
750
|
/**
|
|
797
751
|
* Returns the error from the nearest ancestor <Await /> value
|
|
798
752
|
*/
|
|
799
|
-
|
|
800
753
|
function useAsyncError() {
|
|
801
754
|
let value = React.useContext(AwaitContext);
|
|
802
755
|
return value == null ? void 0 : value._error;
|
|
803
756
|
}
|
|
804
757
|
let blockerId = 0;
|
|
758
|
+
|
|
805
759
|
/**
|
|
806
760
|
* Allow the application to block navigations within the SPA and present the
|
|
807
761
|
* user a confirmation dialog to confirm the navigation. Mostly used to avoid
|
|
808
762
|
* using half-filled form data. This does not handle hard-reloads or
|
|
809
763
|
* cross-origin navigations.
|
|
810
764
|
*/
|
|
811
|
-
|
|
812
765
|
function useBlocker(shouldBlock) {
|
|
813
766
|
let {
|
|
814
767
|
router
|
|
@@ -818,18 +771,20 @@ function useBlocker(shouldBlock) {
|
|
|
818
771
|
let blockerFunction = React.useCallback(args => {
|
|
819
772
|
return typeof shouldBlock === "function" ? !!shouldBlock(args) : !!shouldBlock;
|
|
820
773
|
}, [shouldBlock]);
|
|
821
|
-
let blocker = router.getBlocker(blockerKey, blockerFunction);
|
|
774
|
+
let blocker = router.getBlocker(blockerKey, blockerFunction);
|
|
822
775
|
|
|
823
|
-
|
|
824
|
-
|
|
776
|
+
// Cleanup on unmount
|
|
777
|
+
React.useEffect(() => () => router.deleteBlocker(blockerKey), [router, blockerKey]);
|
|
825
778
|
|
|
779
|
+
// Prefer the blocker from state since DataRouterContext is memoized so this
|
|
780
|
+
// ensures we update on blocker state updates
|
|
826
781
|
return state.blockers.get(blockerKey) || blocker;
|
|
827
782
|
}
|
|
783
|
+
|
|
828
784
|
/**
|
|
829
785
|
* Stable version of useNavigate that is used when we are in the context of
|
|
830
786
|
* a RouterProvider.
|
|
831
787
|
*/
|
|
832
|
-
|
|
833
788
|
function useNavigateStable() {
|
|
834
789
|
let {
|
|
835
790
|
router
|
|
@@ -843,12 +798,11 @@ function useNavigateStable() {
|
|
|
843
798
|
if (options === void 0) {
|
|
844
799
|
options = {};
|
|
845
800
|
}
|
|
801
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(activeRef.current, navigateEffectWarning) : void 0;
|
|
846
802
|
|
|
847
|
-
|
|
803
|
+
// Short circuit here since if this happens on first render the navigate
|
|
848
804
|
// is useless because we haven't wired up our router subscriber yet
|
|
849
|
-
|
|
850
805
|
if (!activeRef.current) return;
|
|
851
|
-
|
|
852
806
|
if (typeof to === "number") {
|
|
853
807
|
router.navigate(to);
|
|
854
808
|
} else {
|
|
@@ -859,9 +813,7 @@ function useNavigateStable() {
|
|
|
859
813
|
}, [router, id]);
|
|
860
814
|
return navigate;
|
|
861
815
|
}
|
|
862
|
-
|
|
863
816
|
const alreadyWarned = {};
|
|
864
|
-
|
|
865
817
|
function warningOnce(key, cond, message) {
|
|
866
818
|
if (!cond && !alreadyWarned[key]) {
|
|
867
819
|
alreadyWarned[key] = true;
|
|
@@ -879,7 +831,10 @@ function RouterProvider(_ref) {
|
|
|
879
831
|
} = _ref;
|
|
880
832
|
// Need to use a layout effect here so we are subscribed early enough to
|
|
881
833
|
// pick up on any render-driven redirects/navigations (useEffect/<Navigate>)
|
|
882
|
-
let [state,
|
|
834
|
+
let [state, setStateImpl] = React.useState(router.state);
|
|
835
|
+
let setState = React.useCallback(newState => {
|
|
836
|
+
"startTransition" in React ? React.startTransition(() => setStateImpl(newState)) : setStateImpl(newState);
|
|
837
|
+
}, [setStateImpl]);
|
|
883
838
|
React.useLayoutEffect(() => router.subscribe(setState), [router, setState]);
|
|
884
839
|
let navigator = React.useMemo(() => {
|
|
885
840
|
return {
|
|
@@ -903,28 +858,28 @@ function RouterProvider(_ref) {
|
|
|
903
858
|
navigator,
|
|
904
859
|
static: false,
|
|
905
860
|
basename
|
|
906
|
-
}), [router, navigator, basename]);
|
|
861
|
+
}), [router, navigator, basename]);
|
|
862
|
+
|
|
863
|
+
// The fragment and {null} here are important! We need them to keep React 18's
|
|
907
864
|
// useId happy when we are server-rendering since we may have a <script> here
|
|
908
865
|
// containing the hydrated server-side staticContext (from StaticRouterProvider).
|
|
909
866
|
// useId relies on the component tree structure to generate deterministic id's
|
|
910
867
|
// so we need to ensure it remains the same on the client even though
|
|
911
868
|
// we don't need the <script> tag
|
|
912
|
-
|
|
913
869
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DataRouterContext.Provider, {
|
|
914
870
|
value: dataRouterContext
|
|
915
871
|
}, /*#__PURE__*/React.createElement(DataRouterStateContext.Provider, {
|
|
916
872
|
value: state
|
|
917
873
|
}, /*#__PURE__*/React.createElement(Router, {
|
|
918
|
-
basename:
|
|
919
|
-
location:
|
|
920
|
-
navigationType:
|
|
874
|
+
basename: basename,
|
|
875
|
+
location: state.location,
|
|
876
|
+
navigationType: state.historyAction,
|
|
921
877
|
navigator: navigator
|
|
922
|
-
},
|
|
878
|
+
}, state.initialized ? /*#__PURE__*/React.createElement(DataRoutes, {
|
|
923
879
|
routes: router.routes,
|
|
924
880
|
state: state
|
|
925
881
|
}) : fallbackElement))), null);
|
|
926
882
|
}
|
|
927
|
-
|
|
928
883
|
function DataRoutes(_ref2) {
|
|
929
884
|
let {
|
|
930
885
|
routes,
|
|
@@ -932,7 +887,6 @@ function DataRoutes(_ref2) {
|
|
|
932
887
|
} = _ref2;
|
|
933
888
|
return useRoutesImpl(routes, undefined, state);
|
|
934
889
|
}
|
|
935
|
-
|
|
936
890
|
/**
|
|
937
891
|
* A <Router> that stores all entries in memory.
|
|
938
892
|
*
|
|
@@ -946,7 +900,6 @@ function MemoryRouter(_ref3) {
|
|
|
946
900
|
initialIndex
|
|
947
901
|
} = _ref3;
|
|
948
902
|
let historyRef = React.useRef();
|
|
949
|
-
|
|
950
903
|
if (historyRef.current == null) {
|
|
951
904
|
historyRef.current = createMemoryHistory({
|
|
952
905
|
initialEntries,
|
|
@@ -954,13 +907,15 @@ function MemoryRouter(_ref3) {
|
|
|
954
907
|
v5Compat: true
|
|
955
908
|
});
|
|
956
909
|
}
|
|
957
|
-
|
|
958
910
|
let history = historyRef.current;
|
|
959
|
-
let [state,
|
|
911
|
+
let [state, setStateImpl] = React.useState({
|
|
960
912
|
action: history.action,
|
|
961
913
|
location: history.location
|
|
962
914
|
});
|
|
963
|
-
React.
|
|
915
|
+
let setState = React.useCallback(newState => {
|
|
916
|
+
"startTransition" in React ? React.startTransition(() => setStateImpl(newState)) : setStateImpl(newState);
|
|
917
|
+
}, [setStateImpl]);
|
|
918
|
+
React.useLayoutEffect(() => history.listen(setState), [history, setState]);
|
|
964
919
|
return /*#__PURE__*/React.createElement(Router, {
|
|
965
920
|
basename: basename,
|
|
966
921
|
children: children,
|
|
@@ -969,7 +924,6 @@ function MemoryRouter(_ref3) {
|
|
|
969
924
|
navigator: history
|
|
970
925
|
});
|
|
971
926
|
}
|
|
972
|
-
|
|
973
927
|
/**
|
|
974
928
|
* Changes the current location.
|
|
975
929
|
*
|
|
@@ -996,9 +950,10 @@ function Navigate(_ref4) {
|
|
|
996
950
|
let {
|
|
997
951
|
pathname: locationPathname
|
|
998
952
|
} = useLocation();
|
|
999
|
-
let navigate = useNavigate();
|
|
1000
|
-
// StrictMode they navigate to the same place
|
|
953
|
+
let navigate = useNavigate();
|
|
1001
954
|
|
|
955
|
+
// Resolve the path outside of the effect so that when effects run twice in
|
|
956
|
+
// StrictMode they navigate to the same place
|
|
1002
957
|
let path = resolveTo(to, UNSAFE_getPathContributingMatches(matches).map(match => match.pathnameBase), locationPathname, relative === "path");
|
|
1003
958
|
let jsonPath = JSON.stringify(path);
|
|
1004
959
|
React.useEffect(() => navigate(JSON.parse(jsonPath), {
|
|
@@ -1008,7 +963,6 @@ function Navigate(_ref4) {
|
|
|
1008
963
|
}), [navigate, jsonPath, relative, replace, state]);
|
|
1009
964
|
return null;
|
|
1010
965
|
}
|
|
1011
|
-
|
|
1012
966
|
/**
|
|
1013
967
|
* Renders the child route's element, if there is one.
|
|
1014
968
|
*
|
|
@@ -1017,7 +971,6 @@ function Navigate(_ref4) {
|
|
|
1017
971
|
function Outlet(props) {
|
|
1018
972
|
return useOutlet(props.context);
|
|
1019
973
|
}
|
|
1020
|
-
|
|
1021
974
|
/**
|
|
1022
975
|
* Declares an element that should be rendered at a certain URL path.
|
|
1023
976
|
*
|
|
@@ -1026,7 +979,6 @@ function Outlet(props) {
|
|
|
1026
979
|
function Route(_props) {
|
|
1027
980
|
process.env.NODE_ENV !== "production" ? UNSAFE_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>.") : UNSAFE_invariant(false) ;
|
|
1028
981
|
}
|
|
1029
|
-
|
|
1030
982
|
/**
|
|
1031
983
|
* Provides location context for the rest of the app.
|
|
1032
984
|
*
|
|
@@ -1045,20 +997,19 @@ function Router(_ref5) {
|
|
|
1045
997
|
navigator,
|
|
1046
998
|
static: staticProp = false
|
|
1047
999
|
} = _ref5;
|
|
1048
|
-
!!useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "You cannot render a <Router> inside another <Router>." + " You should never have more than one in your app.") : UNSAFE_invariant(false) : void 0;
|
|
1049
|
-
// the enforcement of trailing slashes throughout the app
|
|
1000
|
+
!!useInRouterContext() ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "You cannot render a <Router> inside another <Router>." + " You should never have more than one in your app.") : UNSAFE_invariant(false) : void 0;
|
|
1050
1001
|
|
|
1002
|
+
// Preserve trailing slashes on basename, so we can let the user control
|
|
1003
|
+
// the enforcement of trailing slashes throughout the app
|
|
1051
1004
|
let basename = basenameProp.replace(/^\/*/, "/");
|
|
1052
1005
|
let navigationContext = React.useMemo(() => ({
|
|
1053
1006
|
basename,
|
|
1054
1007
|
navigator,
|
|
1055
1008
|
static: staticProp
|
|
1056
1009
|
}), [basename, navigator, staticProp]);
|
|
1057
|
-
|
|
1058
1010
|
if (typeof locationProp === "string") {
|
|
1059
1011
|
locationProp = parsePath(locationProp);
|
|
1060
1012
|
}
|
|
1061
|
-
|
|
1062
1013
|
let {
|
|
1063
1014
|
pathname = "/",
|
|
1064
1015
|
search = "",
|
|
@@ -1068,11 +1019,9 @@ function Router(_ref5) {
|
|
|
1068
1019
|
} = locationProp;
|
|
1069
1020
|
let locationContext = React.useMemo(() => {
|
|
1070
1021
|
let trailingPathname = stripBasename(pathname, basename);
|
|
1071
|
-
|
|
1072
1022
|
if (trailingPathname == null) {
|
|
1073
1023
|
return null;
|
|
1074
1024
|
}
|
|
1075
|
-
|
|
1076
1025
|
return {
|
|
1077
1026
|
location: {
|
|
1078
1027
|
pathname: trailingPathname,
|
|
@@ -1085,11 +1034,9 @@ function Router(_ref5) {
|
|
|
1085
1034
|
};
|
|
1086
1035
|
}, [basename, pathname, search, hash, state, key, navigationType]);
|
|
1087
1036
|
process.env.NODE_ENV !== "production" ? UNSAFE_warning(locationContext != null, "<Router basename=\"" + basename + "\"> is not able to match the URL " + ("\"" + pathname + search + hash + "\" because it does not start with the ") + "basename, so the <Router> won't render anything.") : void 0;
|
|
1088
|
-
|
|
1089
1037
|
if (locationContext == null) {
|
|
1090
1038
|
return null;
|
|
1091
1039
|
}
|
|
1092
|
-
|
|
1093
1040
|
return /*#__PURE__*/React.createElement(NavigationContext.Provider, {
|
|
1094
1041
|
value: navigationContext
|
|
1095
1042
|
}, /*#__PURE__*/React.createElement(LocationContext.Provider, {
|
|
@@ -1097,7 +1044,6 @@ function Router(_ref5) {
|
|
|
1097
1044
|
value: locationContext
|
|
1098
1045
|
}));
|
|
1099
1046
|
}
|
|
1100
|
-
|
|
1101
1047
|
/**
|
|
1102
1048
|
* A container for a nested tree of <Route> elements that renders the branch
|
|
1103
1049
|
* that best matches the current location.
|
|
@@ -1111,7 +1057,6 @@ function Routes(_ref6) {
|
|
|
1111
1057
|
} = _ref6;
|
|
1112
1058
|
return useRoutes(createRoutesFromChildren(children), location);
|
|
1113
1059
|
}
|
|
1114
|
-
|
|
1115
1060
|
/**
|
|
1116
1061
|
* Component to use for rendering lazily loaded data from returning defer()
|
|
1117
1062
|
* in a loader function
|
|
@@ -1128,15 +1073,12 @@ function Await(_ref7) {
|
|
|
1128
1073
|
}, /*#__PURE__*/React.createElement(ResolveAwait, null, children));
|
|
1129
1074
|
}
|
|
1130
1075
|
var AwaitRenderStatus;
|
|
1131
|
-
|
|
1132
1076
|
(function (AwaitRenderStatus) {
|
|
1133
1077
|
AwaitRenderStatus[AwaitRenderStatus["pending"] = 0] = "pending";
|
|
1134
1078
|
AwaitRenderStatus[AwaitRenderStatus["success"] = 1] = "success";
|
|
1135
1079
|
AwaitRenderStatus[AwaitRenderStatus["error"] = 2] = "error";
|
|
1136
1080
|
})(AwaitRenderStatus || (AwaitRenderStatus = {}));
|
|
1137
|
-
|
|
1138
1081
|
const neverSettledPromise = new Promise(() => {});
|
|
1139
|
-
|
|
1140
1082
|
class AwaitErrorBoundary extends React.Component {
|
|
1141
1083
|
constructor(props) {
|
|
1142
1084
|
super(props);
|
|
@@ -1144,17 +1086,14 @@ class AwaitErrorBoundary extends React.Component {
|
|
|
1144
1086
|
error: null
|
|
1145
1087
|
};
|
|
1146
1088
|
}
|
|
1147
|
-
|
|
1148
1089
|
static getDerivedStateFromError(error) {
|
|
1149
1090
|
return {
|
|
1150
1091
|
error
|
|
1151
1092
|
};
|
|
1152
1093
|
}
|
|
1153
|
-
|
|
1154
1094
|
componentDidCatch(error, errorInfo) {
|
|
1155
1095
|
console.error("<Await> caught the following error during render", error, errorInfo);
|
|
1156
1096
|
}
|
|
1157
|
-
|
|
1158
1097
|
render() {
|
|
1159
1098
|
let {
|
|
1160
1099
|
children,
|
|
@@ -1163,7 +1102,6 @@ class AwaitErrorBoundary extends React.Component {
|
|
|
1163
1102
|
} = this.props;
|
|
1164
1103
|
let promise = null;
|
|
1165
1104
|
let status = AwaitRenderStatus.pending;
|
|
1166
|
-
|
|
1167
1105
|
if (!(resolve instanceof Promise)) {
|
|
1168
1106
|
// Didn't get a promise - provide as a resolved promise
|
|
1169
1107
|
status = AwaitRenderStatus.success;
|
|
@@ -1179,7 +1117,6 @@ class AwaitErrorBoundary extends React.Component {
|
|
|
1179
1117
|
status = AwaitRenderStatus.error;
|
|
1180
1118
|
let renderError = this.state.error;
|
|
1181
1119
|
promise = Promise.reject().catch(() => {}); // Avoid unhandled rejection warnings
|
|
1182
|
-
|
|
1183
1120
|
Object.defineProperty(promise, "_tracked", {
|
|
1184
1121
|
get: () => true
|
|
1185
1122
|
});
|
|
@@ -1202,17 +1139,14 @@ class AwaitErrorBoundary extends React.Component {
|
|
|
1202
1139
|
get: () => error
|
|
1203
1140
|
}));
|
|
1204
1141
|
}
|
|
1205
|
-
|
|
1206
1142
|
if (status === AwaitRenderStatus.error && promise._error instanceof AbortedDeferredError) {
|
|
1207
1143
|
// Freeze the UI by throwing a never resolved promise
|
|
1208
1144
|
throw neverSettledPromise;
|
|
1209
1145
|
}
|
|
1210
|
-
|
|
1211
1146
|
if (status === AwaitRenderStatus.error && !errorElement) {
|
|
1212
1147
|
// No errorElement, throw to the nearest route-level error boundary
|
|
1213
1148
|
throw promise._error;
|
|
1214
1149
|
}
|
|
1215
|
-
|
|
1216
1150
|
if (status === AwaitRenderStatus.error) {
|
|
1217
1151
|
// Render via our errorElement
|
|
1218
1152
|
return /*#__PURE__*/React.createElement(AwaitContext.Provider, {
|
|
@@ -1220,26 +1154,23 @@ class AwaitErrorBoundary extends React.Component {
|
|
|
1220
1154
|
children: errorElement
|
|
1221
1155
|
});
|
|
1222
1156
|
}
|
|
1223
|
-
|
|
1224
1157
|
if (status === AwaitRenderStatus.success) {
|
|
1225
1158
|
// Render children with resolved value
|
|
1226
1159
|
return /*#__PURE__*/React.createElement(AwaitContext.Provider, {
|
|
1227
1160
|
value: promise,
|
|
1228
1161
|
children: children
|
|
1229
1162
|
});
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1163
|
+
}
|
|
1232
1164
|
|
|
1165
|
+
// Throw to the suspense boundary
|
|
1233
1166
|
throw promise;
|
|
1234
1167
|
}
|
|
1235
|
-
|
|
1236
1168
|
}
|
|
1169
|
+
|
|
1237
1170
|
/**
|
|
1238
1171
|
* @private
|
|
1239
1172
|
* Indirection to leverage useAsyncValue for a render-prop API on <Await>
|
|
1240
1173
|
*/
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
1174
|
function ResolveAwait(_ref8) {
|
|
1244
1175
|
let {
|
|
1245
1176
|
children
|
|
@@ -1247,7 +1178,9 @@ function ResolveAwait(_ref8) {
|
|
|
1247
1178
|
let data = useAsyncValue();
|
|
1248
1179
|
let toRender = typeof children === "function" ? children(data) : children;
|
|
1249
1180
|
return /*#__PURE__*/React.createElement(React.Fragment, null, toRender);
|
|
1250
|
-
}
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
1251
1184
|
// UTILS
|
|
1252
1185
|
///////////////////////////////////////////////////////////////////////////////
|
|
1253
1186
|
|
|
@@ -1258,13 +1191,10 @@ function ResolveAwait(_ref8) {
|
|
|
1258
1191
|
*
|
|
1259
1192
|
* @see https://reactrouter.com/utils/create-routes-from-children
|
|
1260
1193
|
*/
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
1194
|
function createRoutesFromChildren(children, parentPath) {
|
|
1264
1195
|
if (parentPath === void 0) {
|
|
1265
1196
|
parentPath = [];
|
|
1266
1197
|
}
|
|
1267
|
-
|
|
1268
1198
|
let routes = [];
|
|
1269
1199
|
React.Children.forEach(children, (element, index) => {
|
|
1270
1200
|
if (! /*#__PURE__*/React.isValidElement(element)) {
|
|
@@ -1272,15 +1202,12 @@ function createRoutesFromChildren(children, parentPath) {
|
|
|
1272
1202
|
// conditionals in their route config.
|
|
1273
1203
|
return;
|
|
1274
1204
|
}
|
|
1275
|
-
|
|
1276
1205
|
let treePath = [...parentPath, index];
|
|
1277
|
-
|
|
1278
1206
|
if (element.type === React.Fragment) {
|
|
1279
1207
|
// Transparently support React.Fragment and its children.
|
|
1280
1208
|
routes.push.apply(routes, createRoutesFromChildren(element.props.children, treePath));
|
|
1281
1209
|
return;
|
|
1282
1210
|
}
|
|
1283
|
-
|
|
1284
1211
|
!(element.type === Route) ? process.env.NODE_ENV !== "production" ? UNSAFE_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>") : UNSAFE_invariant(false) : void 0;
|
|
1285
1212
|
!(!element.props.index || !element.props.children) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "An index route cannot have child routes.") : UNSAFE_invariant(false) : void 0;
|
|
1286
1213
|
let route = {
|
|
@@ -1299,19 +1226,17 @@ function createRoutesFromChildren(children, parentPath) {
|
|
|
1299
1226
|
handle: element.props.handle,
|
|
1300
1227
|
lazy: element.props.lazy
|
|
1301
1228
|
};
|
|
1302
|
-
|
|
1303
1229
|
if (element.props.children) {
|
|
1304
1230
|
route.children = createRoutesFromChildren(element.props.children, treePath);
|
|
1305
1231
|
}
|
|
1306
|
-
|
|
1307
1232
|
routes.push(route);
|
|
1308
1233
|
});
|
|
1309
1234
|
return routes;
|
|
1310
1235
|
}
|
|
1236
|
+
|
|
1311
1237
|
/**
|
|
1312
1238
|
* Renders the result of `matchRoutes()` into a React element.
|
|
1313
1239
|
*/
|
|
1314
|
-
|
|
1315
1240
|
function renderMatches(matches) {
|
|
1316
1241
|
return _renderMatches(matches);
|
|
1317
1242
|
}
|
|
@@ -1322,36 +1247,30 @@ function mapRouteProperties(route) {
|
|
|
1322
1247
|
// there if you change this -- please and thank you!
|
|
1323
1248
|
hasErrorBoundary: route.ErrorBoundary != null || route.errorElement != null
|
|
1324
1249
|
};
|
|
1325
|
-
|
|
1326
1250
|
if (route.Component) {
|
|
1327
1251
|
if (process.env.NODE_ENV !== "production") {
|
|
1328
1252
|
if (route.element) {
|
|
1329
1253
|
process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "You should not include both `Component` and `element` on your route - " + "`Component` will be used.") : void 0;
|
|
1330
1254
|
}
|
|
1331
1255
|
}
|
|
1332
|
-
|
|
1333
1256
|
Object.assign(updates, {
|
|
1334
1257
|
element: /*#__PURE__*/React.createElement(route.Component),
|
|
1335
1258
|
Component: undefined
|
|
1336
1259
|
});
|
|
1337
1260
|
}
|
|
1338
|
-
|
|
1339
1261
|
if (route.ErrorBoundary) {
|
|
1340
1262
|
if (process.env.NODE_ENV !== "production") {
|
|
1341
1263
|
if (route.errorElement) {
|
|
1342
1264
|
process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "You should not include both `ErrorBoundary` and `errorElement` on your route - " + "`ErrorBoundary` will be used.") : void 0;
|
|
1343
1265
|
}
|
|
1344
1266
|
}
|
|
1345
|
-
|
|
1346
1267
|
Object.assign(updates, {
|
|
1347
1268
|
errorElement: /*#__PURE__*/React.createElement(route.ErrorBoundary),
|
|
1348
1269
|
ErrorBoundary: undefined
|
|
1349
1270
|
});
|
|
1350
1271
|
}
|
|
1351
|
-
|
|
1352
1272
|
return updates;
|
|
1353
1273
|
}
|
|
1354
|
-
|
|
1355
1274
|
function createMemoryRouter(routes, opts) {
|
|
1356
1275
|
return createRouter({
|
|
1357
1276
|
basename: opts == null ? void 0 : opts.basename,
|
|
@@ -1366,7 +1285,7 @@ function createMemoryRouter(routes, opts) {
|
|
|
1366
1285
|
routes,
|
|
1367
1286
|
mapRouteProperties
|
|
1368
1287
|
}).initialize();
|
|
1369
|
-
}
|
|
1288
|
+
}
|
|
1370
1289
|
|
|
1371
1290
|
export { Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RouteContext as UNSAFE_RouteContext, mapRouteProperties as UNSAFE_mapRouteProperties, useRouteId as UNSAFE_useRouteId, useRoutesImpl as UNSAFE_useRoutesImpl, createMemoryRouter, createRoutesFromChildren, createRoutesFromChildren as createRoutesFromElements, renderMatches, useBlocker as unstable_useBlocker, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes };
|
|
1372
1291
|
//# sourceMappingURL=index.js.map
|