UNPKG

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