react-router 4.0.0 → 4.2.0

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/MemoryRouter.js CHANGED
@@ -2,10 +2,18 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
 
5
+ var _warning = require('warning');
6
+
7
+ var _warning2 = _interopRequireDefault(_warning);
8
+
5
9
  var _react = require('react');
6
10
 
7
11
  var _react2 = _interopRequireDefault(_react);
8
12
 
13
+ var _propTypes = require('prop-types');
14
+
15
+ var _propTypes2 = _interopRequireDefault(_propTypes);
16
+
9
17
  var _createMemoryHistory = require('history/createMemoryHistory');
10
18
 
11
19
  var _createMemoryHistory2 = _interopRequireDefault(_createMemoryHistory);
@@ -40,6 +48,10 @@ var MemoryRouter = function (_React$Component) {
40
48
  return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.history = (0, _createMemoryHistory2.default)(_this.props), _temp), _possibleConstructorReturn(_this, _ret);
41
49
  }
42
50
 
51
+ MemoryRouter.prototype.componentWillMount = function componentWillMount() {
52
+ (0, _warning2.default)(!this.props.history, '<MemoryRouter> ignores the history prop. To use a custom history, ' + 'use `import { Router }` instead of `import { MemoryRouter as Router }`.');
53
+ };
54
+
43
55
  MemoryRouter.prototype.render = function render() {
44
56
  return _react2.default.createElement(_Router2.default, { history: this.history, children: this.props.children });
45
57
  };
@@ -48,10 +60,10 @@ var MemoryRouter = function (_React$Component) {
48
60
  }(_react2.default.Component);
49
61
 
50
62
  MemoryRouter.propTypes = {
51
- initialEntries: _react.PropTypes.array,
52
- initialIndex: _react.PropTypes.number,
53
- getUserConfirmation: _react.PropTypes.func,
54
- keyLength: _react.PropTypes.number,
55
- children: _react.PropTypes.node
63
+ initialEntries: _propTypes2.default.array,
64
+ initialIndex: _propTypes2.default.number,
65
+ getUserConfirmation: _propTypes2.default.func,
66
+ keyLength: _propTypes2.default.number,
67
+ children: _propTypes2.default.node
56
68
  };
57
69
  exports.default = MemoryRouter;
package/Prompt.js CHANGED
@@ -6,6 +6,14 @@ var _react = require('react');
6
6
 
7
7
  var _react2 = _interopRequireDefault(_react);
8
8
 
9
+ var _propTypes = require('prop-types');
10
+
11
+ var _propTypes2 = _interopRequireDefault(_propTypes);
12
+
13
+ var _invariant = require('invariant');
14
+
15
+ var _invariant2 = _interopRequireDefault(_invariant);
16
+
9
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
18
 
11
19
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -41,6 +49,8 @@ var Prompt = function (_React$Component) {
41
49
  };
42
50
 
43
51
  Prompt.prototype.componentWillMount = function componentWillMount() {
52
+ (0, _invariant2.default)(this.context.router, 'You should not use <Prompt> outside a <Router>');
53
+
44
54
  if (this.props.when) this.enable(this.props.message);
45
55
  };
46
56
 
@@ -64,16 +74,16 @@ var Prompt = function (_React$Component) {
64
74
  }(_react2.default.Component);
65
75
 
66
76
  Prompt.propTypes = {
67
- when: _react.PropTypes.bool,
68
- message: _react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.string]).isRequired
77
+ when: _propTypes2.default.bool,
78
+ message: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.string]).isRequired
69
79
  };
70
80
  Prompt.defaultProps = {
71
81
  when: true
72
82
  };
73
83
  Prompt.contextTypes = {
74
- router: _react.PropTypes.shape({
75
- history: _react.PropTypes.shape({
76
- block: _react.PropTypes.func.isRequired
84
+ router: _propTypes2.default.shape({
85
+ history: _propTypes2.default.shape({
86
+ block: _propTypes2.default.func.isRequired
77
87
  }).isRequired
78
88
  }).isRequired
79
89
  };
package/README.md CHANGED
@@ -8,6 +8,9 @@ Using [npm](https://www.npmjs.com/):
8
8
 
9
9
  $ npm install --save react-router
10
10
 
11
+ **Note:** This package provides the core routing functionality for React Router, but you might not want to install it directly. If you are writing an application that will run in the browser, you should instead install `react-router-dom`. Similarly, if you are writing a React Native application, you should instead install `react-router-native`. Both of those will install `react-router` as a dependency.
12
+
13
+
11
14
  Then with a module bundler like [webpack](https://webpack.github.io/), use as you would anything else:
12
15
 
13
16
  ```js
package/Redirect.js CHANGED
@@ -6,6 +6,20 @@ var _react = require('react');
6
6
 
7
7
  var _react2 = _interopRequireDefault(_react);
8
8
 
9
+ var _propTypes = require('prop-types');
10
+
11
+ var _propTypes2 = _interopRequireDefault(_propTypes);
12
+
13
+ var _warning = require('warning');
14
+
15
+ var _warning2 = _interopRequireDefault(_warning);
16
+
17
+ var _invariant = require('invariant');
18
+
19
+ var _invariant2 = _interopRequireDefault(_invariant);
20
+
21
+ var _history = require('history');
22
+
9
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
24
 
11
25
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -15,7 +29,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
15
29
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
16
30
 
17
31
  /**
18
- * The public API for updating the location programatically
32
+ * The public API for updating the location programmatically
19
33
  * with a component.
20
34
  */
21
35
  var Redirect = function (_React$Component) {
@@ -32,6 +46,8 @@ var Redirect = function (_React$Component) {
32
46
  };
33
47
 
34
48
  Redirect.prototype.componentWillMount = function componentWillMount() {
49
+ (0, _invariant2.default)(this.context.router, 'You should not use <Redirect> outside a <Router>');
50
+
35
51
  if (this.isStatic()) this.perform();
36
52
  };
37
53
 
@@ -39,6 +55,18 @@ var Redirect = function (_React$Component) {
39
55
  if (!this.isStatic()) this.perform();
40
56
  };
41
57
 
58
+ Redirect.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
59
+ var prevTo = (0, _history.createLocation)(prevProps.to);
60
+ var nextTo = (0, _history.createLocation)(this.props.to);
61
+
62
+ if ((0, _history.locationsAreEqual)(prevTo, nextTo)) {
63
+ (0, _warning2.default)(false, 'You tried to redirect to the same route you\'re currently on: ' + ('"' + nextTo.pathname + nextTo.search + '"'));
64
+ return;
65
+ }
66
+
67
+ this.perform();
68
+ };
69
+
42
70
  Redirect.prototype.perform = function perform() {
43
71
  var history = this.context.router.history;
44
72
  var _props = this.props,
@@ -61,20 +89,20 @@ var Redirect = function (_React$Component) {
61
89
  }(_react2.default.Component);
62
90
 
63
91
  Redirect.propTypes = {
64
- push: _react.PropTypes.bool,
65
- from: _react.PropTypes.string,
66
- to: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.object])
92
+ push: _propTypes2.default.bool,
93
+ from: _propTypes2.default.string,
94
+ to: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object]).isRequired
67
95
  };
68
96
  Redirect.defaultProps = {
69
97
  push: false
70
98
  };
71
99
  Redirect.contextTypes = {
72
- router: _react.PropTypes.shape({
73
- history: _react.PropTypes.shape({
74
- push: _react.PropTypes.func.isRequired,
75
- replace: _react.PropTypes.func.isRequired
100
+ router: _propTypes2.default.shape({
101
+ history: _propTypes2.default.shape({
102
+ push: _propTypes2.default.func.isRequired,
103
+ replace: _propTypes2.default.func.isRequired
76
104
  }).isRequired,
77
- staticContext: _react.PropTypes.object
105
+ staticContext: _propTypes2.default.object
78
106
  }).isRequired
79
107
  };
80
108
  exports.default = Redirect;
package/Route.js CHANGED
@@ -8,10 +8,18 @@ var _warning = require('warning');
8
8
 
9
9
  var _warning2 = _interopRequireDefault(_warning);
10
10
 
11
+ var _invariant = require('invariant');
12
+
13
+ var _invariant2 = _interopRequireDefault(_invariant);
14
+
11
15
  var _react = require('react');
12
16
 
13
17
  var _react2 = _interopRequireDefault(_react);
14
18
 
19
+ var _propTypes = require('prop-types');
20
+
21
+ var _propTypes2 = _interopRequireDefault(_propTypes);
22
+
15
23
  var _matchPath = require('./matchPath');
16
24
 
17
25
  var _matchPath2 = _interopRequireDefault(_matchPath);
@@ -24,9 +32,14 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
24
32
 
25
33
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
26
34
 
35
+ var isEmptyChildren = function isEmptyChildren(children) {
36
+ return _react2.default.Children.count(children) === 0;
37
+ };
38
+
27
39
  /**
28
40
  * The public API for matching a single path and rendering.
29
41
  */
42
+
30
43
  var Route = function (_React$Component) {
31
44
  _inherits(Route, _React$Component);
32
45
 
@@ -45,8 +58,6 @@ var Route = function (_React$Component) {
45
58
  }
46
59
 
47
60
  Route.prototype.getChildContext = function getChildContext() {
48
- var router = this.context.router;
49
-
50
61
  return {
51
62
  router: _extends({}, this.context.router, {
52
63
  route: {
@@ -57,33 +68,31 @@ var Route = function (_React$Component) {
57
68
  };
58
69
  };
59
70
 
60
- Route.prototype.computeMatch = function computeMatch(_ref, _ref2) {
71
+ Route.prototype.computeMatch = function computeMatch(_ref, router) {
61
72
  var computedMatch = _ref.computedMatch,
62
73
  location = _ref.location,
63
74
  path = _ref.path,
64
75
  strict = _ref.strict,
65
- exact = _ref.exact;
66
- var route = _ref2.route;
76
+ exact = _ref.exact,
77
+ sensitive = _ref.sensitive;
67
78
 
68
79
  if (computedMatch) return computedMatch; // <Switch> already computed the match for us
69
80
 
81
+ (0, _invariant2.default)(router, 'You should not use <Route> or withRouter() outside a <Router>');
82
+
83
+ var route = router.route;
84
+
70
85
  var pathname = (location || route.location).pathname;
71
86
 
72
- return path ? (0, _matchPath2.default)(pathname, { path: path, strict: strict, exact: exact }) : route.match;
87
+ return path ? (0, _matchPath2.default)(pathname, { path: path, strict: strict, exact: exact, sensitive: sensitive }) : route.match;
73
88
  };
74
89
 
75
90
  Route.prototype.componentWillMount = function componentWillMount() {
76
- var _props = this.props,
77
- component = _props.component,
78
- render = _props.render,
79
- children = _props.children;
91
+ (0, _warning2.default)(!(this.props.component && this.props.render), 'You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored');
80
92
 
93
+ (0, _warning2.default)(!(this.props.component && this.props.children && !isEmptyChildren(this.props.children)), 'You should not use <Route component> and <Route children> in the same route; <Route children> will be ignored');
81
94
 
82
- (0, _warning2.default)(!(component && render), 'You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored');
83
-
84
- (0, _warning2.default)(!(component && children), 'You should not use <Route component> and <Route children> in the same route; <Route children> will be ignored');
85
-
86
- (0, _warning2.default)(!(render && children), 'You should not use <Route render> and <Route children> in the same route; <Route children> will be ignored');
95
+ (0, _warning2.default)(!(this.props.render && this.props.children && !isEmptyChildren(this.props.children)), 'You should not use <Route render> and <Route children> in the same route; <Route children> will be ignored');
87
96
  };
88
97
 
89
98
  Route.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextContext) {
@@ -98,10 +107,10 @@ var Route = function (_React$Component) {
98
107
 
99
108
  Route.prototype.render = function render() {
100
109
  var match = this.state.match;
101
- var _props2 = this.props,
102
- children = _props2.children,
103
- component = _props2.component,
104
- render = _props2.render;
110
+ var _props = this.props,
111
+ children = _props.children,
112
+ component = _props.component,
113
+ render = _props.render;
105
114
  var _context$router = this.context.router,
106
115
  history = _context$router.history,
107
116
  route = _context$router.route,
@@ -113,31 +122,31 @@ var Route = function (_React$Component) {
113
122
  return component ? // component prop gets first priority, only called if there's a match
114
123
  match ? _react2.default.createElement(component, props) : null : render ? // render prop is next, only called if there's a match
115
124
  match ? render(props) : null : children ? // children come last, always called
116
- typeof children === 'function' ? children(props) : !Array.isArray(children) || children.length ? // Preact defaults to empty children array
117
- _react2.default.Children.only(children) : null : null;
125
+ typeof children === 'function' ? children(props) : !isEmptyChildren(children) ? _react2.default.Children.only(children) : null : null;
118
126
  };
119
127
 
120
128
  return Route;
121
129
  }(_react2.default.Component);
122
130
 
123
131
  Route.propTypes = {
124
- computedMatch: _react.PropTypes.object, // private, from <Switch>
125
- path: _react.PropTypes.string,
126
- exact: _react.PropTypes.bool,
127
- strict: _react.PropTypes.bool,
128
- component: _react.PropTypes.func,
129
- render: _react.PropTypes.func,
130
- children: _react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.node]),
131
- location: _react.PropTypes.object
132
+ computedMatch: _propTypes2.default.object, // private, from <Switch>
133
+ path: _propTypes2.default.string,
134
+ exact: _propTypes2.default.bool,
135
+ strict: _propTypes2.default.bool,
136
+ sensitive: _propTypes2.default.bool,
137
+ component: _propTypes2.default.func,
138
+ render: _propTypes2.default.func,
139
+ children: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.node]),
140
+ location: _propTypes2.default.object
132
141
  };
133
142
  Route.contextTypes = {
134
- router: _react.PropTypes.shape({
135
- history: _react.PropTypes.object.isRequired,
136
- route: _react.PropTypes.object.isRequired,
137
- staticContext: _react.PropTypes.object
143
+ router: _propTypes2.default.shape({
144
+ history: _propTypes2.default.object.isRequired,
145
+ route: _propTypes2.default.object.isRequired,
146
+ staticContext: _propTypes2.default.object
138
147
  })
139
148
  };
140
149
  Route.childContextTypes = {
141
- router: _react.PropTypes.object.isRequired
150
+ router: _propTypes2.default.object.isRequired
142
151
  };
143
152
  exports.default = Route;
package/Router.js CHANGED
@@ -16,6 +16,10 @@ var _react = require('react');
16
16
 
17
17
  var _react2 = _interopRequireDefault(_react);
18
18
 
19
+ var _propTypes = require('prop-types');
20
+
21
+ var _propTypes2 = _interopRequireDefault(_propTypes);
22
+
19
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
24
 
21
25
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -103,13 +107,13 @@ var Router = function (_React$Component) {
103
107
  }(_react2.default.Component);
104
108
 
105
109
  Router.propTypes = {
106
- history: _react.PropTypes.object.isRequired,
107
- children: _react.PropTypes.node
110
+ history: _propTypes2.default.object.isRequired,
111
+ children: _propTypes2.default.node
108
112
  };
109
113
  Router.contextTypes = {
110
- router: _react.PropTypes.object
114
+ router: _propTypes2.default.object
111
115
  };
112
116
  Router.childContextTypes = {
113
- router: _react.PropTypes.object.isRequired
117
+ router: _propTypes2.default.object.isRequired
114
118
  };
115
119
  exports.default = Router;
package/StaticRouter.js CHANGED
@@ -4,6 +4,10 @@ exports.__esModule = true;
4
4
 
5
5
  var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
6
6
 
7
+ var _warning = require('warning');
8
+
9
+ var _warning2 = _interopRequireDefault(_warning);
10
+
7
11
  var _invariant = require('invariant');
8
12
 
9
13
  var _invariant2 = _interopRequireDefault(_invariant);
@@ -12,6 +16,10 @@ var _react = require('react');
12
16
 
13
17
  var _react2 = _interopRequireDefault(_react);
14
18
 
19
+ var _propTypes = require('prop-types');
20
+
21
+ var _propTypes2 = _interopRequireDefault(_propTypes);
22
+
15
23
  var _PathUtils = require('history/PathUtils');
16
24
 
17
25
  var _Router = require('./Router');
@@ -132,6 +140,10 @@ var StaticRouter = function (_React$Component) {
132
140
  };
133
141
  };
134
142
 
143
+ StaticRouter.prototype.componentWillMount = function componentWillMount() {
144
+ (0, _warning2.default)(!this.props.history, '<StaticRouter> ignores the history prop. To use a custom history, ' + 'use `import { Router }` instead of `import { StaticRouter as Router }`.');
145
+ };
146
+
135
147
  StaticRouter.prototype.render = function render() {
136
148
  var _props = this.props,
137
149
  basename = _props.basename,
@@ -159,15 +171,15 @@ var StaticRouter = function (_React$Component) {
159
171
  }(_react2.default.Component);
160
172
 
161
173
  StaticRouter.propTypes = {
162
- basename: _react.PropTypes.string,
163
- context: _react.PropTypes.object.isRequired,
164
- location: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.object])
174
+ basename: _propTypes2.default.string,
175
+ context: _propTypes2.default.object.isRequired,
176
+ location: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object])
165
177
  };
166
178
  StaticRouter.defaultProps = {
167
179
  basename: '',
168
180
  location: '/'
169
181
  };
170
182
  StaticRouter.childContextTypes = {
171
- router: _react.PropTypes.object.isRequired
183
+ router: _propTypes2.default.object.isRequired
172
184
  };
173
185
  exports.default = StaticRouter;
package/Switch.js CHANGED
@@ -6,10 +6,18 @@ var _react = require('react');
6
6
 
7
7
  var _react2 = _interopRequireDefault(_react);
8
8
 
9
+ var _propTypes = require('prop-types');
10
+
11
+ var _propTypes2 = _interopRequireDefault(_propTypes);
12
+
9
13
  var _warning = require('warning');
10
14
 
11
15
  var _warning2 = _interopRequireDefault(_warning);
12
16
 
17
+ var _invariant = require('invariant');
18
+
19
+ var _invariant2 = _interopRequireDefault(_invariant);
20
+
13
21
  var _matchPath = require('./matchPath');
14
22
 
15
23
  var _matchPath2 = _interopRequireDefault(_matchPath);
@@ -34,6 +42,10 @@ var Switch = function (_React$Component) {
34
42
  return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
35
43
  }
36
44
 
45
+ Switch.prototype.componentWillMount = function componentWillMount() {
46
+ (0, _invariant2.default)(this.context.router, 'You should not use <Switch> outside a <Router>');
47
+ };
48
+
37
49
  Switch.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
38
50
  (0, _warning2.default)(!(nextProps.location && !this.props.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.');
39
51
 
@@ -49,17 +61,20 @@ var Switch = function (_React$Component) {
49
61
  var match = void 0,
50
62
  child = void 0;
51
63
  _react2.default.Children.forEach(children, function (element) {
64
+ if (!_react2.default.isValidElement(element)) return;
65
+
52
66
  var _element$props = element.props,
53
67
  pathProp = _element$props.path,
54
68
  exact = _element$props.exact,
55
69
  strict = _element$props.strict,
70
+ sensitive = _element$props.sensitive,
56
71
  from = _element$props.from;
57
72
 
58
73
  var path = pathProp || from;
59
74
 
60
75
  if (match == null) {
61
76
  child = element;
62
- match = path ? (0, _matchPath2.default)(location.pathname, { path: path, exact: exact, strict: strict }) : route.match;
77
+ match = path ? (0, _matchPath2.default)(location.pathname, { path: path, exact: exact, strict: strict, sensitive: sensitive }) : route.match;
63
78
  }
64
79
  });
65
80
 
@@ -70,12 +85,12 @@ var Switch = function (_React$Component) {
70
85
  }(_react2.default.Component);
71
86
 
72
87
  Switch.contextTypes = {
73
- router: _react.PropTypes.shape({
74
- route: _react.PropTypes.object.isRequired
88
+ router: _propTypes2.default.shape({
89
+ route: _propTypes2.default.object.isRequired
75
90
  }).isRequired
76
91
  };
77
92
  Switch.propTypes = {
78
- children: _react.PropTypes.node,
79
- location: _react.PropTypes.object
93
+ children: _propTypes2.default.node,
94
+ location: _propTypes2.default.object
80
95
  };
81
96
  exports.default = Switch;
@@ -4,7 +4,9 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
4
4
 
5
5
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
6
6
 
7
- import React, { PropTypes } from 'react';
7
+ import warning from 'warning';
8
+ import React from 'react';
9
+ import PropTypes from 'prop-types';
8
10
  import createHistory from 'history/createMemoryHistory';
9
11
  import Router from './Router';
10
12
 
@@ -27,6 +29,10 @@ var MemoryRouter = function (_React$Component) {
27
29
  return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.history = createHistory(_this.props), _temp), _possibleConstructorReturn(_this, _ret);
28
30
  }
29
31
 
32
+ MemoryRouter.prototype.componentWillMount = function componentWillMount() {
33
+ warning(!this.props.history, '<MemoryRouter> ignores the history prop. To use a custom history, ' + 'use `import { Router }` instead of `import { MemoryRouter as Router }`.');
34
+ };
35
+
30
36
  MemoryRouter.prototype.render = function render() {
31
37
  return React.createElement(Router, { history: this.history, children: this.props.children });
32
38
  };
package/es/Prompt.js CHANGED
@@ -4,7 +4,9 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
4
4
 
5
5
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
6
6
 
7
- import React, { PropTypes } from 'react';
7
+ import React from 'react';
8
+ import PropTypes from 'prop-types';
9
+ import invariant from 'invariant';
8
10
 
9
11
  /**
10
12
  * The public API for prompting the user before navigating away
@@ -34,6 +36,8 @@ var Prompt = function (_React$Component) {
34
36
  };
35
37
 
36
38
  Prompt.prototype.componentWillMount = function componentWillMount() {
39
+ invariant(this.context.router, 'You should not use <Prompt> outside a <Router>');
40
+
37
41
  if (this.props.when) this.enable(this.props.message);
38
42
  };
39
43
 
package/es/Redirect.js CHANGED
@@ -4,10 +4,14 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
4
4
 
5
5
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
6
6
 
7
- import React, { PropTypes } from 'react';
7
+ import React from 'react';
8
+ import PropTypes from 'prop-types';
9
+ import warning from 'warning';
10
+ import invariant from 'invariant';
11
+ import { createLocation, locationsAreEqual } from 'history';
8
12
 
9
13
  /**
10
- * The public API for updating the location programatically
14
+ * The public API for updating the location programmatically
11
15
  * with a component.
12
16
  */
13
17
 
@@ -25,6 +29,8 @@ var Redirect = function (_React$Component) {
25
29
  };
26
30
 
27
31
  Redirect.prototype.componentWillMount = function componentWillMount() {
32
+ invariant(this.context.router, 'You should not use <Redirect> outside a <Router>');
33
+
28
34
  if (this.isStatic()) this.perform();
29
35
  };
30
36
 
@@ -32,6 +38,18 @@ var Redirect = function (_React$Component) {
32
38
  if (!this.isStatic()) this.perform();
33
39
  };
34
40
 
41
+ Redirect.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
42
+ var prevTo = createLocation(prevProps.to);
43
+ var nextTo = createLocation(this.props.to);
44
+
45
+ if (locationsAreEqual(prevTo, nextTo)) {
46
+ warning(false, 'You tried to redirect to the same route you\'re currently on: ' + ('"' + nextTo.pathname + nextTo.search + '"'));
47
+ return;
48
+ }
49
+
50
+ this.perform();
51
+ };
52
+
35
53
  Redirect.prototype.perform = function perform() {
36
54
  var history = this.context.router.history;
37
55
  var _props = this.props,
@@ -56,7 +74,7 @@ var Redirect = function (_React$Component) {
56
74
  Redirect.propTypes = {
57
75
  push: PropTypes.bool,
58
76
  from: PropTypes.string,
59
- to: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
77
+ to: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired
60
78
  };
61
79
  Redirect.defaultProps = {
62
80
  push: false