UNPKG

25.5 kBJavaScriptView Raw
1import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
2import React from 'react';
3import PropTypes from 'prop-types';
4import { createMemoryHistory, createLocation, locationsAreEqual, createPath } from 'history';
5import warning from 'tiny-warning';
6import createContext from 'mini-create-react-context';
7import invariant from 'tiny-invariant';
8import _extends from '@babel/runtime/helpers/esm/extends';
9import pathToRegexp from 'path-to-regexp';
10import { isValidElementType } from 'react-is';
11import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/esm/objectWithoutPropertiesLoose';
12import hoistStatics from 'hoist-non-react-statics';
13
14// TODO: Replace with React.createContext once we can assume React 16+
15
16var createNamedContext = function createNamedContext(name) {
17 var context = createContext();
18 context.displayName = name;
19 return context;
20};
21
22var historyContext =
23/*#__PURE__*/
24createNamedContext("Router-History");
25
26// TODO: Replace with React.createContext once we can assume React 16+
27
28var createNamedContext$1 = function createNamedContext(name) {
29 var context = createContext();
30 context.displayName = name;
31 return context;
32};
33
34var context =
35/*#__PURE__*/
36createNamedContext$1("Router");
37
38/**
39 * The public API for putting history on context.
40 */
41
42var Router =
43/*#__PURE__*/
44function (_React$Component) {
45 _inheritsLoose(Router, _React$Component);
46
47 Router.computeRootMatch = function computeRootMatch(pathname) {
48 return {
49 path: "/",
50 url: "/",
51 params: {},
52 isExact: pathname === "/"
53 };
54 };
55
56 function Router(props) {
57 var _this;
58
59 _this = _React$Component.call(this, props) || this;
60 _this.state = {
61 location: props.history.location
62 }; // This is a bit of a hack. We have to start listening for location
63 // changes here in the constructor in case there are any <Redirect>s
64 // on the initial render. If there are, they will replace/push when
65 // they mount and since cDM fires in children before parents, we may
66 // get a new location before the <Router> is mounted.
67
68 _this._isMounted = false;
69 _this._pendingLocation = null;
70
71 if (!props.staticContext) {
72 _this.unlisten = props.history.listen(function (location) {
73 if (_this._isMounted) {
74 _this.setState({
75 location: location
76 });
77 } else {
78 _this._pendingLocation = location;
79 }
80 });
81 }
82
83 return _this;
84 }
85
86 var _proto = Router.prototype;
87
88 _proto.componentDidMount = function componentDidMount() {
89 this._isMounted = true;
90
91 if (this._pendingLocation) {
92 this.setState({
93 location: this._pendingLocation
94 });
95 }
96 };
97
98 _proto.componentWillUnmount = function componentWillUnmount() {
99 if (this.unlisten) this.unlisten();
100 };
101
102 _proto.render = function render() {
103 return React.createElement(context.Provider, {
104 value: {
105 history: this.props.history,
106 location: this.state.location,
107 match: Router.computeRootMatch(this.state.location.pathname),
108 staticContext: this.props.staticContext
109 }
110 }, React.createElement(historyContext.Provider, {
111 children: this.props.children || null,
112 value: this.props.history
113 }));
114 };
115
116 return Router;
117}(React.Component);
118
119if (process.env.NODE_ENV !== "production") {
120 Router.propTypes = {
121 children: PropTypes.node,
122 history: PropTypes.object.isRequired,
123 staticContext: PropTypes.object
124 };
125
126 Router.prototype.componentDidUpdate = function (prevProps) {
127 process.env.NODE_ENV !== "production" ? warning(prevProps.history === this.props.history, "You cannot change <Router history>") : void 0;
128 };
129}
130
131/**
132 * The public API for a <Router> that stores location in memory.
133 */
134
135var MemoryRouter =
136/*#__PURE__*/
137function (_React$Component) {
138 _inheritsLoose(MemoryRouter, _React$Component);
139
140 function MemoryRouter() {
141 var _this;
142
143 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
144 args[_key] = arguments[_key];
145 }
146
147 _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
148 _this.history = createMemoryHistory(_this.props);
149 return _this;
150 }
151
152 var _proto = MemoryRouter.prototype;
153
154 _proto.render = function render() {
155 return React.createElement(Router, {
156 history: this.history,
157 children: this.props.children
158 });
159 };
160
161 return MemoryRouter;
162}(React.Component);
163
164if (process.env.NODE_ENV !== "production") {
165 MemoryRouter.propTypes = {
166 initialEntries: PropTypes.array,
167 initialIndex: PropTypes.number,
168 getUserConfirmation: PropTypes.func,
169 keyLength: PropTypes.number,
170 children: PropTypes.node
171 };
172
173 MemoryRouter.prototype.componentDidMount = function () {
174 process.env.NODE_ENV !== "production" ? warning(!this.props.history, "<MemoryRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { MemoryRouter as Router }`.") : void 0;
175 };
176}
177
178var Lifecycle =
179/*#__PURE__*/
180function (_React$Component) {
181 _inheritsLoose(Lifecycle, _React$Component);
182
183 function Lifecycle() {
184 return _React$Component.apply(this, arguments) || this;
185 }
186
187 var _proto = Lifecycle.prototype;
188
189 _proto.componentDidMount = function componentDidMount() {
190 if (this.props.onMount) this.props.onMount.call(this, this);
191 };
192
193 _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
194 if (this.props.onUpdate) this.props.onUpdate.call(this, this, prevProps);
195 };
196
197 _proto.componentWillUnmount = function componentWillUnmount() {
198 if (this.props.onUnmount) this.props.onUnmount.call(this, this);
199 };
200
201 _proto.render = function render() {
202 return null;
203 };
204
205 return Lifecycle;
206}(React.Component);
207
208/**
209 * The public API for prompting the user before navigating away from a screen.
210 */
211
212function Prompt(_ref) {
213 var message = _ref.message,
214 _ref$when = _ref.when,
215 when = _ref$when === void 0 ? true : _ref$when;
216 return React.createElement(context.Consumer, null, function (context) {
217 !context ? process.env.NODE_ENV !== "production" ? invariant(false, "You should not use <Prompt> outside a <Router>") : invariant(false) : void 0;
218 if (!when || context.staticContext) return null;
219 var method = context.history.block;
220 return React.createElement(Lifecycle, {
221 onMount: function onMount(self) {
222 self.release = method(message);
223 },
224 onUpdate: function onUpdate(self, prevProps) {
225 if (prevProps.message !== message) {
226 self.release();
227 self.release = method(message);
228 }
229 },
230 onUnmount: function onUnmount(self) {
231 self.release();
232 },
233 message: message
234 });
235 });
236}
237
238if (process.env.NODE_ENV !== "production") {
239 var messageType = PropTypes.oneOfType([PropTypes.func, PropTypes.string]);
240 Prompt.propTypes = {
241 when: PropTypes.bool,
242 message: messageType.isRequired
243 };
244}
245
246var cache = {};
247var cacheLimit = 10000;
248var cacheCount = 0;
249
250function compilePath(path) {
251 if (cache[path]) return cache[path];
252 var generator = pathToRegexp.compile(path);
253
254 if (cacheCount < cacheLimit) {
255 cache[path] = generator;
256 cacheCount++;
257 }
258
259 return generator;
260}
261/**
262 * Public API for generating a URL pathname from a path and parameters.
263 */
264
265
266function generatePath(path, params) {
267 if (path === void 0) {
268 path = "/";
269 }
270
271 if (params === void 0) {
272 params = {};
273 }
274
275 return path === "/" ? path : compilePath(path)(params, {
276 pretty: true
277 });
278}
279
280/**
281 * The public API for navigating programmatically with a component.
282 */
283
284function Redirect(_ref) {
285 var computedMatch = _ref.computedMatch,
286 to = _ref.to,
287 _ref$push = _ref.push,
288 push = _ref$push === void 0 ? false : _ref$push;
289 return React.createElement(context.Consumer, null, function (context) {
290 !context ? process.env.NODE_ENV !== "production" ? invariant(false, "You should not use <Redirect> outside a <Router>") : invariant(false) : void 0;
291 var history = context.history,
292 staticContext = context.staticContext;
293 var method = push ? history.push : history.replace;
294 var location = createLocation(computedMatch ? typeof to === "string" ? generatePath(to, computedMatch.params) : _extends({}, to, {
295 pathname: generatePath(to.pathname, computedMatch.params)
296 }) : to); // When rendering in a static context,
297 // set the new location immediately.
298
299 if (staticContext) {
300 method(location);
301 return null;
302 }
303
304 return React.createElement(Lifecycle, {
305 onMount: function onMount() {
306 method(location);
307 },
308 onUpdate: function onUpdate(self, prevProps) {
309 var prevLocation = createLocation(prevProps.to);
310
311 if (!locationsAreEqual(prevLocation, _extends({}, location, {
312 key: prevLocation.key
313 }))) {
314 method(location);
315 }
316 },
317 to: to
318 });
319 });
320}
321
322if (process.env.NODE_ENV !== "production") {
323 Redirect.propTypes = {
324 push: PropTypes.bool,
325 from: PropTypes.string,
326 to: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired
327 };
328}
329
330var cache$1 = {};
331var cacheLimit$1 = 10000;
332var cacheCount$1 = 0;
333
334function compilePath$1(path, options) {
335 var cacheKey = "" + options.end + options.strict + options.sensitive;
336 var pathCache = cache$1[cacheKey] || (cache$1[cacheKey] = {});
337 if (pathCache[path]) return pathCache[path];
338 var keys = [];
339 var regexp = pathToRegexp(path, keys, options);
340 var result = {
341 regexp: regexp,
342 keys: keys
343 };
344
345 if (cacheCount$1 < cacheLimit$1) {
346 pathCache[path] = result;
347 cacheCount$1++;
348 }
349
350 return result;
351}
352/**
353 * Public API for matching a URL pathname to a path.
354 */
355
356
357function matchPath(pathname, options) {
358 if (options === void 0) {
359 options = {};
360 }
361
362 if (typeof options === "string" || Array.isArray(options)) {
363 options = {
364 path: options
365 };
366 }
367
368 var _options = options,
369 path = _options.path,
370 _options$exact = _options.exact,
371 exact = _options$exact === void 0 ? false : _options$exact,
372 _options$strict = _options.strict,
373 strict = _options$strict === void 0 ? false : _options$strict,
374 _options$sensitive = _options.sensitive,
375 sensitive = _options$sensitive === void 0 ? false : _options$sensitive;
376 var paths = [].concat(path);
377 return paths.reduce(function (matched, path) {
378 if (!path && path !== "") return null;
379 if (matched) return matched;
380
381 var _compilePath = compilePath$1(path, {
382 end: exact,
383 strict: strict,
384 sensitive: sensitive
385 }),
386 regexp = _compilePath.regexp,
387 keys = _compilePath.keys;
388
389 var match = regexp.exec(pathname);
390 if (!match) return null;
391 var url = match[0],
392 values = match.slice(1);
393 var isExact = pathname === url;
394 if (exact && !isExact) return null;
395 return {
396 path: path,
397 // the path used to match
398 url: path === "/" && url === "" ? "/" : url,
399 // the matched portion of the URL
400 isExact: isExact,
401 // whether or not we matched exactly
402 params: keys.reduce(function (memo, key, index) {
403 memo[key.name] = values[index];
404 return memo;
405 }, {})
406 };
407 }, null);
408}
409
410function isEmptyChildren(children) {
411 return React.Children.count(children) === 0;
412}
413
414function evalChildrenDev(children, props, path) {
415 var value = children(props);
416 process.env.NODE_ENV !== "production" ? warning(value !== undefined, "You returned `undefined` from the `children` function of " + ("<Route" + (path ? " path=\"" + path + "\"" : "") + ">, but you ") + "should have returned a React element or `null`") : void 0;
417 return value || null;
418}
419/**
420 * The public API for matching a single path and rendering.
421 */
422
423
424var Route =
425/*#__PURE__*/
426function (_React$Component) {
427 _inheritsLoose(Route, _React$Component);
428
429 function Route() {
430 return _React$Component.apply(this, arguments) || this;
431 }
432
433 var _proto = Route.prototype;
434
435 _proto.render = function render() {
436 var _this = this;
437
438 return React.createElement(context.Consumer, null, function (context$1) {
439 !context$1 ? process.env.NODE_ENV !== "production" ? invariant(false, "You should not use <Route> outside a <Router>") : invariant(false) : void 0;
440 var location = _this.props.location || context$1.location;
441 var match = _this.props.computedMatch ? _this.props.computedMatch // <Switch> already computed the match for us
442 : _this.props.path ? matchPath(location.pathname, _this.props) : context$1.match;
443
444 var props = _extends({}, context$1, {
445 location: location,
446 match: match
447 });
448
449 var _this$props = _this.props,
450 children = _this$props.children,
451 component = _this$props.component,
452 render = _this$props.render; // Preact uses an empty array as children by
453 // default, so use null if that's the case.
454
455 if (Array.isArray(children) && children.length === 0) {
456 children = null;
457 }
458
459 return React.createElement(context.Provider, {
460 value: props
461 }, props.match ? children ? typeof children === "function" ? process.env.NODE_ENV !== "production" ? evalChildrenDev(children, props, _this.props.path) : children(props) : children : component ? React.createElement(component, props) : render ? render(props) : null : typeof children === "function" ? process.env.NODE_ENV !== "production" ? evalChildrenDev(children, props, _this.props.path) : children(props) : null);
462 });
463 };
464
465 return Route;
466}(React.Component);
467
468if (process.env.NODE_ENV !== "production") {
469 Route.propTypes = {
470 children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
471 component: function component(props, propName) {
472 if (props[propName] && !isValidElementType(props[propName])) {
473 return new Error("Invalid prop 'component' supplied to 'Route': the prop is not a valid React component");
474 }
475 },
476 exact: PropTypes.bool,
477 location: PropTypes.object,
478 path: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
479 render: PropTypes.func,
480 sensitive: PropTypes.bool,
481 strict: PropTypes.bool
482 };
483
484 Route.prototype.componentDidMount = function () {
485 process.env.NODE_ENV !== "production" ? warning(!(this.props.children && !isEmptyChildren(this.props.children) && this.props.component), "You should not use <Route component> and <Route children> in the same route; <Route component> will be ignored") : void 0;
486 process.env.NODE_ENV !== "production" ? warning(!(this.props.children && !isEmptyChildren(this.props.children) && this.props.render), "You should not use <Route render> and <Route children> in the same route; <Route render> will be ignored") : void 0;
487 process.env.NODE_ENV !== "production" ? warning(!(this.props.component && this.props.render), "You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored") : void 0;
488 };
489
490 Route.prototype.componentDidUpdate = function (prevProps) {
491 process.env.NODE_ENV !== "production" ? warning(!(this.props.location && !prevProps.location), '<Route> elements should not change from uncontrolled to controlled (or vice versa). You initially used no "location" prop and then provided one on a subsequent render.') : void 0;
492 process.env.NODE_ENV !== "production" ? warning(!(!this.props.location && prevProps.location), '<Route> elements should not change from controlled to uncontrolled (or vice versa). You provided a "location" prop initially but omitted it on a subsequent render.') : void 0;
493 };
494}
495
496function addLeadingSlash(path) {
497 return path.charAt(0) === "/" ? path : "/" + path;
498}
499
500function addBasename(basename, location) {
501 if (!basename) return location;
502 return _extends({}, location, {
503 pathname: addLeadingSlash(basename) + location.pathname
504 });
505}
506
507function stripBasename(basename, location) {
508 if (!basename) return location;
509 var base = addLeadingSlash(basename);
510 if (location.pathname.indexOf(base) !== 0) return location;
511 return _extends({}, location, {
512 pathname: location.pathname.substr(base.length)
513 });
514}
515
516function createURL(location) {
517 return typeof location === "string" ? location : createPath(location);
518}
519
520function staticHandler(methodName) {
521 return function () {
522 process.env.NODE_ENV !== "production" ? invariant(false, "You cannot %s with <StaticRouter>", methodName) : invariant(false) ;
523 };
524}
525
526function noop() {}
527/**
528 * The public top-level API for a "static" <Router>, so-called because it
529 * can't actually change the current location. Instead, it just records
530 * location changes in a context object. Useful mainly in testing and
531 * server-rendering scenarios.
532 */
533
534
535var StaticRouter =
536/*#__PURE__*/
537function (_React$Component) {
538 _inheritsLoose(StaticRouter, _React$Component);
539
540 function StaticRouter() {
541 var _this;
542
543 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
544 args[_key] = arguments[_key];
545 }
546
547 _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
548
549 _this.handlePush = function (location) {
550 return _this.navigateTo(location, "PUSH");
551 };
552
553 _this.handleReplace = function (location) {
554 return _this.navigateTo(location, "REPLACE");
555 };
556
557 _this.handleListen = function () {
558 return noop;
559 };
560
561 _this.handleBlock = function () {
562 return noop;
563 };
564
565 return _this;
566 }
567
568 var _proto = StaticRouter.prototype;
569
570 _proto.navigateTo = function navigateTo(location, action) {
571 var _this$props = this.props,
572 _this$props$basename = _this$props.basename,
573 basename = _this$props$basename === void 0 ? "" : _this$props$basename,
574 _this$props$context = _this$props.context,
575 context = _this$props$context === void 0 ? {} : _this$props$context;
576 context.action = action;
577 context.location = addBasename(basename, createLocation(location));
578 context.url = createURL(context.location);
579 };
580
581 _proto.render = function render() {
582 var _this$props2 = this.props,
583 _this$props2$basename = _this$props2.basename,
584 basename = _this$props2$basename === void 0 ? "" : _this$props2$basename,
585 _this$props2$context = _this$props2.context,
586 context = _this$props2$context === void 0 ? {} : _this$props2$context,
587 _this$props2$location = _this$props2.location,
588 location = _this$props2$location === void 0 ? "/" : _this$props2$location,
589 rest = _objectWithoutPropertiesLoose(_this$props2, ["basename", "context", "location"]);
590
591 var history = {
592 createHref: function createHref(path) {
593 return addLeadingSlash(basename + createURL(path));
594 },
595 action: "POP",
596 location: stripBasename(basename, createLocation(location)),
597 push: this.handlePush,
598 replace: this.handleReplace,
599 go: staticHandler("go"),
600 goBack: staticHandler("goBack"),
601 goForward: staticHandler("goForward"),
602 listen: this.handleListen,
603 block: this.handleBlock
604 };
605 return React.createElement(Router, _extends({}, rest, {
606 history: history,
607 staticContext: context
608 }));
609 };
610
611 return StaticRouter;
612}(React.Component);
613
614if (process.env.NODE_ENV !== "production") {
615 StaticRouter.propTypes = {
616 basename: PropTypes.string,
617 context: PropTypes.object,
618 location: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
619 };
620
621 StaticRouter.prototype.componentDidMount = function () {
622 process.env.NODE_ENV !== "production" ? warning(!this.props.history, "<StaticRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { StaticRouter as Router }`.") : void 0;
623 };
624}
625
626/**
627 * The public API for rendering the first <Route> that matches.
628 */
629
630var Switch =
631/*#__PURE__*/
632function (_React$Component) {
633 _inheritsLoose(Switch, _React$Component);
634
635 function Switch() {
636 return _React$Component.apply(this, arguments) || this;
637 }
638
639 var _proto = Switch.prototype;
640
641 _proto.render = function render() {
642 var _this = this;
643
644 return React.createElement(context.Consumer, null, function (context) {
645 !context ? process.env.NODE_ENV !== "production" ? invariant(false, "You should not use <Switch> outside a <Router>") : invariant(false) : void 0;
646 var location = _this.props.location || context.location;
647 var element, match; // We use React.Children.forEach instead of React.Children.toArray().find()
648 // here because toArray adds keys to all child elements and we do not want
649 // to trigger an unmount/remount for two <Route>s that render the same
650 // component at different URLs.
651
652 React.Children.forEach(_this.props.children, function (child) {
653 if (match == null && React.isValidElement(child)) {
654 element = child;
655 var path = child.props.path || child.props.from;
656 match = path ? matchPath(location.pathname, _extends({}, child.props, {
657 path: path
658 })) : context.match;
659 }
660 });
661 return match ? React.cloneElement(element, {
662 location: location,
663 computedMatch: match
664 }) : null;
665 });
666 };
667
668 return Switch;
669}(React.Component);
670
671if (process.env.NODE_ENV !== "production") {
672 Switch.propTypes = {
673 children: PropTypes.node,
674 location: PropTypes.object
675 };
676
677 Switch.prototype.componentDidUpdate = function (prevProps) {
678 process.env.NODE_ENV !== "production" ? warning(!(this.props.location && !prevProps.location), '<Switch> elements should not change from uncontrolled to controlled (or vice versa). You initially used no "location" prop and then provided one on a subsequent render.') : void 0;
679 process.env.NODE_ENV !== "production" ? warning(!(!this.props.location && prevProps.location), '<Switch> elements should not change from controlled to uncontrolled (or vice versa). You provided a "location" prop initially but omitted it on a subsequent render.') : void 0;
680 };
681}
682
683/**
684 * A public higher-order component to access the imperative API
685 */
686
687function withRouter(Component) {
688 var displayName = "withRouter(" + (Component.displayName || Component.name) + ")";
689
690 var C = function C(props) {
691 var wrappedComponentRef = props.wrappedComponentRef,
692 remainingProps = _objectWithoutPropertiesLoose(props, ["wrappedComponentRef"]);
693
694 return React.createElement(context.Consumer, null, function (context) {
695 !context ? process.env.NODE_ENV !== "production" ? invariant(false, "You should not use <" + displayName + " /> outside a <Router>") : invariant(false) : void 0;
696 return React.createElement(Component, _extends({}, remainingProps, context, {
697 ref: wrappedComponentRef
698 }));
699 });
700 };
701
702 C.displayName = displayName;
703 C.WrappedComponent = Component;
704
705 if (process.env.NODE_ENV !== "production") {
706 C.propTypes = {
707 wrappedComponentRef: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object])
708 };
709 }
710
711 return hoistStatics(C, Component);
712}
713
714var useContext = React.useContext;
715function useHistory() {
716 if (process.env.NODE_ENV !== "production") {
717 !(typeof useContext === "function") ? process.env.NODE_ENV !== "production" ? invariant(false, "You must use React >= 16.8 in order to use useHistory()") : invariant(false) : void 0;
718 }
719
720 return useContext(historyContext);
721}
722function useLocation() {
723 if (process.env.NODE_ENV !== "production") {
724 !(typeof useContext === "function") ? process.env.NODE_ENV !== "production" ? invariant(false, "You must use React >= 16.8 in order to use useLocation()") : invariant(false) : void 0;
725 }
726
727 return useContext(context).location;
728}
729function useParams() {
730 if (process.env.NODE_ENV !== "production") {
731 !(typeof useContext === "function") ? process.env.NODE_ENV !== "production" ? invariant(false, "You must use React >= 16.8 in order to use useParams()") : invariant(false) : void 0;
732 }
733
734 var match = useContext(context).match;
735 return match ? match.params : {};
736}
737function useRouteMatch(path) {
738 if (process.env.NODE_ENV !== "production") {
739 !(typeof useContext === "function") ? process.env.NODE_ENV !== "production" ? invariant(false, "You must use React >= 16.8 in order to use useRouteMatch()") : invariant(false) : void 0;
740 }
741
742 var location = useLocation();
743 var match = useContext(context).match;
744 return path ? matchPath(location.pathname, path) : match;
745}
746
747if (process.env.NODE_ENV !== "production") {
748 if (typeof window !== "undefined") {
749 var global = window;
750 var key = "__react_router_build__";
751 var buildNames = {
752 cjs: "CommonJS",
753 esm: "ES modules",
754 umd: "UMD"
755 };
756
757 if (global[key] && global[key] !== "esm") {
758 var initialBuildName = buildNames[global[key]];
759 var secondaryBuildName = buildNames["esm"]; // TODO: Add link to article that explains in detail how to avoid
760 // loading 2 different builds.
761
762 throw new Error("You are loading the " + secondaryBuildName + " build of React Router " + ("on a page that is already running the " + initialBuildName + " ") + "build, so things won't work right.");
763 }
764
765 global[key] = "esm";
766 }
767}
768
769export { MemoryRouter, Prompt, Redirect, Route, Router, StaticRouter, Switch, historyContext as __HistoryContext, context as __RouterContext, generatePath, matchPath, useHistory, useLocation, useParams, useRouteMatch, withRouter };
770//# sourceMappingURL=react-router.js.map