react-router 4.1.2 → 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 +8 -0
- package/Prompt.js +6 -0
- package/README.md +3 -0
- package/Redirect.js +26 -2
- package/Route.js +26 -19
- package/StaticRouter.js +8 -0
- package/Switch.js +10 -1
- package/es/MemoryRouter.js +5 -0
- package/es/Prompt.js +3 -0
- package/es/Redirect.js +19 -2
- package/es/Route.js +22 -19
- package/es/StaticRouter.js +5 -0
- package/es/Switch.js +7 -1
- package/es/matchPath.js +5 -3
- package/matchPath.js +5 -3
- package/package.json +22 -27
- package/umd/react-router.js +2591 -2191
- package/umd/react-router.min.js +1 -1
package/MemoryRouter.js
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
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);
|
|
@@ -44,6 +48,10 @@ var MemoryRouter = function (_React$Component) {
|
|
|
44
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);
|
|
45
49
|
}
|
|
46
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
|
+
|
|
47
55
|
MemoryRouter.prototype.render = function render() {
|
|
48
56
|
return _react2.default.createElement(_Router2.default, { history: this.history, children: this.props.children });
|
|
49
57
|
};
|
package/Prompt.js
CHANGED
|
@@ -10,6 +10,10 @@ var _propTypes = require('prop-types');
|
|
|
10
10
|
|
|
11
11
|
var _propTypes2 = _interopRequireDefault(_propTypes);
|
|
12
12
|
|
|
13
|
+
var _invariant = require('invariant');
|
|
14
|
+
|
|
15
|
+
var _invariant2 = _interopRequireDefault(_invariant);
|
|
16
|
+
|
|
13
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
18
|
|
|
15
19
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -45,6 +49,8 @@ var Prompt = function (_React$Component) {
|
|
|
45
49
|
};
|
|
46
50
|
|
|
47
51
|
Prompt.prototype.componentWillMount = function componentWillMount() {
|
|
52
|
+
(0, _invariant2.default)(this.context.router, 'You should not use <Prompt> outside a <Router>');
|
|
53
|
+
|
|
48
54
|
if (this.props.when) this.enable(this.props.message);
|
|
49
55
|
};
|
|
50
56
|
|
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
|
@@ -10,6 +10,16 @@ var _propTypes = require('prop-types');
|
|
|
10
10
|
|
|
11
11
|
var _propTypes2 = _interopRequireDefault(_propTypes);
|
|
12
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
|
+
|
|
13
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
24
|
|
|
15
25
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -19,7 +29,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
19
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; }
|
|
20
30
|
|
|
21
31
|
/**
|
|
22
|
-
* The public API for updating the location
|
|
32
|
+
* The public API for updating the location programmatically
|
|
23
33
|
* with a component.
|
|
24
34
|
*/
|
|
25
35
|
var Redirect = function (_React$Component) {
|
|
@@ -36,6 +46,8 @@ var Redirect = function (_React$Component) {
|
|
|
36
46
|
};
|
|
37
47
|
|
|
38
48
|
Redirect.prototype.componentWillMount = function componentWillMount() {
|
|
49
|
+
(0, _invariant2.default)(this.context.router, 'You should not use <Redirect> outside a <Router>');
|
|
50
|
+
|
|
39
51
|
if (this.isStatic()) this.perform();
|
|
40
52
|
};
|
|
41
53
|
|
|
@@ -43,6 +55,18 @@ var Redirect = function (_React$Component) {
|
|
|
43
55
|
if (!this.isStatic()) this.perform();
|
|
44
56
|
};
|
|
45
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
|
+
|
|
46
70
|
Redirect.prototype.perform = function perform() {
|
|
47
71
|
var history = this.context.router.history;
|
|
48
72
|
var _props = this.props,
|
|
@@ -67,7 +91,7 @@ var Redirect = function (_React$Component) {
|
|
|
67
91
|
Redirect.propTypes = {
|
|
68
92
|
push: _propTypes2.default.bool,
|
|
69
93
|
from: _propTypes2.default.string,
|
|
70
|
-
to: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object])
|
|
94
|
+
to: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object]).isRequired
|
|
71
95
|
};
|
|
72
96
|
Redirect.defaultProps = {
|
|
73
97
|
push: false
|
package/Route.js
CHANGED
|
@@ -8,6 +8,10 @@ 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);
|
|
@@ -28,9 +32,14 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
28
32
|
|
|
29
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; }
|
|
30
34
|
|
|
35
|
+
var isEmptyChildren = function isEmptyChildren(children) {
|
|
36
|
+
return _react2.default.Children.count(children) === 0;
|
|
37
|
+
};
|
|
38
|
+
|
|
31
39
|
/**
|
|
32
40
|
* The public API for matching a single path and rendering.
|
|
33
41
|
*/
|
|
42
|
+
|
|
34
43
|
var Route = function (_React$Component) {
|
|
35
44
|
_inherits(Route, _React$Component);
|
|
36
45
|
|
|
@@ -59,33 +68,31 @@ var Route = function (_React$Component) {
|
|
|
59
68
|
};
|
|
60
69
|
};
|
|
61
70
|
|
|
62
|
-
Route.prototype.computeMatch = function computeMatch(_ref,
|
|
71
|
+
Route.prototype.computeMatch = function computeMatch(_ref, router) {
|
|
63
72
|
var computedMatch = _ref.computedMatch,
|
|
64
73
|
location = _ref.location,
|
|
65
74
|
path = _ref.path,
|
|
66
75
|
strict = _ref.strict,
|
|
67
|
-
exact = _ref.exact
|
|
68
|
-
|
|
76
|
+
exact = _ref.exact,
|
|
77
|
+
sensitive = _ref.sensitive;
|
|
69
78
|
|
|
70
79
|
if (computedMatch) return computedMatch; // <Switch> already computed the match for us
|
|
71
80
|
|
|
81
|
+
(0, _invariant2.default)(router, 'You should not use <Route> or withRouter() outside a <Router>');
|
|
82
|
+
|
|
83
|
+
var route = router.route;
|
|
84
|
+
|
|
72
85
|
var pathname = (location || route.location).pathname;
|
|
73
86
|
|
|
74
|
-
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;
|
|
75
88
|
};
|
|
76
89
|
|
|
77
90
|
Route.prototype.componentWillMount = function componentWillMount() {
|
|
78
|
-
|
|
79
|
-
component = _props.component,
|
|
80
|
-
render = _props.render,
|
|
81
|
-
children = _props.children;
|
|
82
|
-
|
|
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');
|
|
83
92
|
|
|
84
|
-
(0, _warning2.default)(!(component &&
|
|
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');
|
|
85
94
|
|
|
86
|
-
(0, _warning2.default)(!(
|
|
87
|
-
|
|
88
|
-
(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');
|
|
89
96
|
};
|
|
90
97
|
|
|
91
98
|
Route.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextContext) {
|
|
@@ -100,10 +107,10 @@ var Route = function (_React$Component) {
|
|
|
100
107
|
|
|
101
108
|
Route.prototype.render = function render() {
|
|
102
109
|
var match = this.state.match;
|
|
103
|
-
var
|
|
104
|
-
children =
|
|
105
|
-
component =
|
|
106
|
-
render =
|
|
110
|
+
var _props = this.props,
|
|
111
|
+
children = _props.children,
|
|
112
|
+
component = _props.component,
|
|
113
|
+
render = _props.render;
|
|
107
114
|
var _context$router = this.context.router,
|
|
108
115
|
history = _context$router.history,
|
|
109
116
|
route = _context$router.route,
|
|
@@ -115,8 +122,7 @@ var Route = function (_React$Component) {
|
|
|
115
122
|
return component ? // component prop gets first priority, only called if there's a match
|
|
116
123
|
match ? _react2.default.createElement(component, props) : null : render ? // render prop is next, only called if there's a match
|
|
117
124
|
match ? render(props) : null : children ? // children come last, always called
|
|
118
|
-
typeof children === 'function' ? children(props) : !
|
|
119
|
-
_react2.default.Children.only(children) : null : null;
|
|
125
|
+
typeof children === 'function' ? children(props) : !isEmptyChildren(children) ? _react2.default.Children.only(children) : null : null;
|
|
120
126
|
};
|
|
121
127
|
|
|
122
128
|
return Route;
|
|
@@ -127,6 +133,7 @@ Route.propTypes = {
|
|
|
127
133
|
path: _propTypes2.default.string,
|
|
128
134
|
exact: _propTypes2.default.bool,
|
|
129
135
|
strict: _propTypes2.default.bool,
|
|
136
|
+
sensitive: _propTypes2.default.bool,
|
|
130
137
|
component: _propTypes2.default.func,
|
|
131
138
|
render: _propTypes2.default.func,
|
|
132
139
|
children: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.node]),
|
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);
|
|
@@ -136,6 +140,10 @@ var StaticRouter = function (_React$Component) {
|
|
|
136
140
|
};
|
|
137
141
|
};
|
|
138
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
|
+
|
|
139
147
|
StaticRouter.prototype.render = function render() {
|
|
140
148
|
var _props = this.props,
|
|
141
149
|
basename = _props.basename,
|
package/Switch.js
CHANGED
|
@@ -14,6 +14,10 @@ var _warning = require('warning');
|
|
|
14
14
|
|
|
15
15
|
var _warning2 = _interopRequireDefault(_warning);
|
|
16
16
|
|
|
17
|
+
var _invariant = require('invariant');
|
|
18
|
+
|
|
19
|
+
var _invariant2 = _interopRequireDefault(_invariant);
|
|
20
|
+
|
|
17
21
|
var _matchPath = require('./matchPath');
|
|
18
22
|
|
|
19
23
|
var _matchPath2 = _interopRequireDefault(_matchPath);
|
|
@@ -38,6 +42,10 @@ var Switch = function (_React$Component) {
|
|
|
38
42
|
return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
|
39
43
|
}
|
|
40
44
|
|
|
45
|
+
Switch.prototype.componentWillMount = function componentWillMount() {
|
|
46
|
+
(0, _invariant2.default)(this.context.router, 'You should not use <Switch> outside a <Router>');
|
|
47
|
+
};
|
|
48
|
+
|
|
41
49
|
Switch.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
|
42
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.');
|
|
43
51
|
|
|
@@ -59,13 +67,14 @@ var Switch = function (_React$Component) {
|
|
|
59
67
|
pathProp = _element$props.path,
|
|
60
68
|
exact = _element$props.exact,
|
|
61
69
|
strict = _element$props.strict,
|
|
70
|
+
sensitive = _element$props.sensitive,
|
|
62
71
|
from = _element$props.from;
|
|
63
72
|
|
|
64
73
|
var path = pathProp || from;
|
|
65
74
|
|
|
66
75
|
if (match == null) {
|
|
67
76
|
child = element;
|
|
68
|
-
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;
|
|
69
78
|
}
|
|
70
79
|
});
|
|
71
80
|
|
package/es/MemoryRouter.js
CHANGED
|
@@ -4,6 +4,7 @@ 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 warning from 'warning';
|
|
7
8
|
import React from 'react';
|
|
8
9
|
import PropTypes from 'prop-types';
|
|
9
10
|
import createHistory from 'history/createMemoryHistory';
|
|
@@ -28,6 +29,10 @@ var MemoryRouter = function (_React$Component) {
|
|
|
28
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);
|
|
29
30
|
}
|
|
30
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
|
+
|
|
31
36
|
MemoryRouter.prototype.render = function render() {
|
|
32
37
|
return React.createElement(Router, { history: this.history, children: this.props.children });
|
|
33
38
|
};
|
package/es/Prompt.js
CHANGED
|
@@ -6,6 +6,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
6
6
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
|
+
import invariant from 'invariant';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* The public API for prompting the user before navigating away
|
|
@@ -35,6 +36,8 @@ var Prompt = function (_React$Component) {
|
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
Prompt.prototype.componentWillMount = function componentWillMount() {
|
|
39
|
+
invariant(this.context.router, 'You should not use <Prompt> outside a <Router>');
|
|
40
|
+
|
|
38
41
|
if (this.props.when) this.enable(this.props.message);
|
|
39
42
|
};
|
|
40
43
|
|
package/es/Redirect.js
CHANGED
|
@@ -6,9 +6,12 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
6
6
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
|
+
import warning from 'warning';
|
|
10
|
+
import invariant from 'invariant';
|
|
11
|
+
import { createLocation, locationsAreEqual } from 'history';
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
|
-
* The public API for updating the location
|
|
14
|
+
* The public API for updating the location programmatically
|
|
12
15
|
* with a component.
|
|
13
16
|
*/
|
|
14
17
|
|
|
@@ -26,6 +29,8 @@ var Redirect = function (_React$Component) {
|
|
|
26
29
|
};
|
|
27
30
|
|
|
28
31
|
Redirect.prototype.componentWillMount = function componentWillMount() {
|
|
32
|
+
invariant(this.context.router, 'You should not use <Redirect> outside a <Router>');
|
|
33
|
+
|
|
29
34
|
if (this.isStatic()) this.perform();
|
|
30
35
|
};
|
|
31
36
|
|
|
@@ -33,6 +38,18 @@ var Redirect = function (_React$Component) {
|
|
|
33
38
|
if (!this.isStatic()) this.perform();
|
|
34
39
|
};
|
|
35
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
|
+
|
|
36
53
|
Redirect.prototype.perform = function perform() {
|
|
37
54
|
var history = this.context.router.history;
|
|
38
55
|
var _props = this.props,
|
|
@@ -57,7 +74,7 @@ var Redirect = function (_React$Component) {
|
|
|
57
74
|
Redirect.propTypes = {
|
|
58
75
|
push: PropTypes.bool,
|
|
59
76
|
from: PropTypes.string,
|
|
60
|
-
to: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
|
|
77
|
+
to: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired
|
|
61
78
|
};
|
|
62
79
|
Redirect.defaultProps = {
|
|
63
80
|
push: false
|
package/es/Route.js
CHANGED
|
@@ -7,10 +7,15 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
7
7
|
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; }
|
|
8
8
|
|
|
9
9
|
import warning from 'warning';
|
|
10
|
+
import invariant from 'invariant';
|
|
10
11
|
import React from 'react';
|
|
11
12
|
import PropTypes from 'prop-types';
|
|
12
13
|
import matchPath from './matchPath';
|
|
13
14
|
|
|
15
|
+
var isEmptyChildren = function isEmptyChildren(children) {
|
|
16
|
+
return React.Children.count(children) === 0;
|
|
17
|
+
};
|
|
18
|
+
|
|
14
19
|
/**
|
|
15
20
|
* The public API for matching a single path and rendering.
|
|
16
21
|
*/
|
|
@@ -43,33 +48,31 @@ var Route = function (_React$Component) {
|
|
|
43
48
|
};
|
|
44
49
|
};
|
|
45
50
|
|
|
46
|
-
Route.prototype.computeMatch = function computeMatch(_ref,
|
|
51
|
+
Route.prototype.computeMatch = function computeMatch(_ref, router) {
|
|
47
52
|
var computedMatch = _ref.computedMatch,
|
|
48
53
|
location = _ref.location,
|
|
49
54
|
path = _ref.path,
|
|
50
55
|
strict = _ref.strict,
|
|
51
|
-
exact = _ref.exact
|
|
52
|
-
|
|
56
|
+
exact = _ref.exact,
|
|
57
|
+
sensitive = _ref.sensitive;
|
|
53
58
|
|
|
54
59
|
if (computedMatch) return computedMatch; // <Switch> already computed the match for us
|
|
55
60
|
|
|
61
|
+
invariant(router, 'You should not use <Route> or withRouter() outside a <Router>');
|
|
62
|
+
|
|
63
|
+
var route = router.route;
|
|
64
|
+
|
|
56
65
|
var pathname = (location || route.location).pathname;
|
|
57
66
|
|
|
58
|
-
return path ? matchPath(pathname, { path: path, strict: strict, exact: exact }) : route.match;
|
|
67
|
+
return path ? matchPath(pathname, { path: path, strict: strict, exact: exact, sensitive: sensitive }) : route.match;
|
|
59
68
|
};
|
|
60
69
|
|
|
61
70
|
Route.prototype.componentWillMount = function componentWillMount() {
|
|
62
|
-
|
|
63
|
-
component = _props.component,
|
|
64
|
-
render = _props.render,
|
|
65
|
-
children = _props.children;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
warning(!(component && render), 'You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored');
|
|
71
|
+
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');
|
|
69
72
|
|
|
70
|
-
warning(!(component && children), 'You should not use <Route component> and <Route children> in the same route; <Route children> will be ignored');
|
|
73
|
+
warning(!(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');
|
|
71
74
|
|
|
72
|
-
warning(!(render && children), 'You should not use <Route render> and <Route children> in the same route; <Route children> will be ignored');
|
|
75
|
+
warning(!(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');
|
|
73
76
|
};
|
|
74
77
|
|
|
75
78
|
Route.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextContext) {
|
|
@@ -84,10 +87,10 @@ var Route = function (_React$Component) {
|
|
|
84
87
|
|
|
85
88
|
Route.prototype.render = function render() {
|
|
86
89
|
var match = this.state.match;
|
|
87
|
-
var
|
|
88
|
-
children =
|
|
89
|
-
component =
|
|
90
|
-
render =
|
|
90
|
+
var _props = this.props,
|
|
91
|
+
children = _props.children,
|
|
92
|
+
component = _props.component,
|
|
93
|
+
render = _props.render;
|
|
91
94
|
var _context$router = this.context.router,
|
|
92
95
|
history = _context$router.history,
|
|
93
96
|
route = _context$router.route,
|
|
@@ -99,8 +102,7 @@ var Route = function (_React$Component) {
|
|
|
99
102
|
return component ? // component prop gets first priority, only called if there's a match
|
|
100
103
|
match ? React.createElement(component, props) : null : render ? // render prop is next, only called if there's a match
|
|
101
104
|
match ? render(props) : null : children ? // children come last, always called
|
|
102
|
-
typeof children === 'function' ? children(props) : !
|
|
103
|
-
React.Children.only(children) : null : null;
|
|
105
|
+
typeof children === 'function' ? children(props) : !isEmptyChildren(children) ? React.Children.only(children) : null : null;
|
|
104
106
|
};
|
|
105
107
|
|
|
106
108
|
return Route;
|
|
@@ -111,6 +113,7 @@ Route.propTypes = {
|
|
|
111
113
|
path: PropTypes.string,
|
|
112
114
|
exact: PropTypes.bool,
|
|
113
115
|
strict: PropTypes.bool,
|
|
116
|
+
sensitive: PropTypes.bool,
|
|
114
117
|
component: PropTypes.func,
|
|
115
118
|
render: PropTypes.func,
|
|
116
119
|
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
|
package/es/StaticRouter.js
CHANGED
|
@@ -8,6 +8,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
8
8
|
|
|
9
9
|
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; }
|
|
10
10
|
|
|
11
|
+
import warning from 'warning';
|
|
11
12
|
import invariant from 'invariant';
|
|
12
13
|
import React from 'react';
|
|
13
14
|
import PropTypes from 'prop-types';
|
|
@@ -118,6 +119,10 @@ var StaticRouter = function (_React$Component) {
|
|
|
118
119
|
};
|
|
119
120
|
};
|
|
120
121
|
|
|
122
|
+
StaticRouter.prototype.componentWillMount = function componentWillMount() {
|
|
123
|
+
warning(!this.props.history, '<StaticRouter> ignores the history prop. To use a custom history, ' + 'use `import { Router }` instead of `import { StaticRouter as Router }`.');
|
|
124
|
+
};
|
|
125
|
+
|
|
121
126
|
StaticRouter.prototype.render = function render() {
|
|
122
127
|
var _props = this.props,
|
|
123
128
|
basename = _props.basename,
|
package/es/Switch.js
CHANGED
|
@@ -7,6 +7,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
9
|
import warning from 'warning';
|
|
10
|
+
import invariant from 'invariant';
|
|
10
11
|
import matchPath from './matchPath';
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -22,6 +23,10 @@ var Switch = function (_React$Component) {
|
|
|
22
23
|
return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
Switch.prototype.componentWillMount = function componentWillMount() {
|
|
27
|
+
invariant(this.context.router, 'You should not use <Switch> outside a <Router>');
|
|
28
|
+
};
|
|
29
|
+
|
|
25
30
|
Switch.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
|
26
31
|
warning(!(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.');
|
|
27
32
|
|
|
@@ -43,13 +48,14 @@ var Switch = function (_React$Component) {
|
|
|
43
48
|
pathProp = _element$props.path,
|
|
44
49
|
exact = _element$props.exact,
|
|
45
50
|
strict = _element$props.strict,
|
|
51
|
+
sensitive = _element$props.sensitive,
|
|
46
52
|
from = _element$props.from;
|
|
47
53
|
|
|
48
54
|
var path = pathProp || from;
|
|
49
55
|
|
|
50
56
|
if (match == null) {
|
|
51
57
|
child = element;
|
|
52
|
-
match = path ? matchPath(location.pathname, { path: path, exact: exact, strict: strict }) : route.match;
|
|
58
|
+
match = path ? matchPath(location.pathname, { path: path, exact: exact, strict: strict, sensitive: sensitive }) : route.match;
|
|
53
59
|
}
|
|
54
60
|
});
|
|
55
61
|
|
package/es/matchPath.js
CHANGED
|
@@ -5,7 +5,7 @@ var cacheLimit = 10000;
|
|
|
5
5
|
var cacheCount = 0;
|
|
6
6
|
|
|
7
7
|
var compilePath = function compilePath(pattern, options) {
|
|
8
|
-
var cacheKey = '' + options.end + options.strict;
|
|
8
|
+
var cacheKey = '' + options.end + options.strict + options.sensitive;
|
|
9
9
|
var cache = patternCache[cacheKey] || (patternCache[cacheKey] = {});
|
|
10
10
|
|
|
11
11
|
if (cache[pattern]) return cache[pattern];
|
|
@@ -36,9 +36,11 @@ var matchPath = function matchPath(pathname) {
|
|
|
36
36
|
_options$exact = _options.exact,
|
|
37
37
|
exact = _options$exact === undefined ? false : _options$exact,
|
|
38
38
|
_options$strict = _options.strict,
|
|
39
|
-
strict = _options$strict === undefined ? false : _options$strict
|
|
39
|
+
strict = _options$strict === undefined ? false : _options$strict,
|
|
40
|
+
_options$sensitive = _options.sensitive,
|
|
41
|
+
sensitive = _options$sensitive === undefined ? false : _options$sensitive;
|
|
40
42
|
|
|
41
|
-
var _compilePath = compilePath(path, { end: exact, strict: strict }),
|
|
43
|
+
var _compilePath = compilePath(path, { end: exact, strict: strict, sensitive: sensitive }),
|
|
42
44
|
re = _compilePath.re,
|
|
43
45
|
keys = _compilePath.keys;
|
|
44
46
|
|
package/matchPath.js
CHANGED
|
@@ -13,7 +13,7 @@ var cacheLimit = 10000;
|
|
|
13
13
|
var cacheCount = 0;
|
|
14
14
|
|
|
15
15
|
var compilePath = function compilePath(pattern, options) {
|
|
16
|
-
var cacheKey = '' + options.end + options.strict;
|
|
16
|
+
var cacheKey = '' + options.end + options.strict + options.sensitive;
|
|
17
17
|
var cache = patternCache[cacheKey] || (patternCache[cacheKey] = {});
|
|
18
18
|
|
|
19
19
|
if (cache[pattern]) return cache[pattern];
|
|
@@ -44,9 +44,11 @@ var matchPath = function matchPath(pathname) {
|
|
|
44
44
|
_options$exact = _options.exact,
|
|
45
45
|
exact = _options$exact === undefined ? false : _options$exact,
|
|
46
46
|
_options$strict = _options.strict,
|
|
47
|
-
strict = _options$strict === undefined ? false : _options$strict
|
|
47
|
+
strict = _options$strict === undefined ? false : _options$strict,
|
|
48
|
+
_options$sensitive = _options.sensitive,
|
|
49
|
+
sensitive = _options$sensitive === undefined ? false : _options$sensitive;
|
|
48
50
|
|
|
49
|
-
var _compilePath = compilePath(path, { end: exact, strict: strict }),
|
|
51
|
+
var _compilePath = compilePath(path, { end: exact, strict: strict, sensitive: sensitive }),
|
|
50
52
|
re = _compilePath.re,
|
|
51
53
|
keys = _compilePath.keys;
|
|
52
54
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-router",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Declarative routing for React",
|
|
5
5
|
"repository": "ReactTraining/react-router",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"Router.js",
|
|
17
17
|
"StaticRouter.js",
|
|
18
18
|
"Switch.js",
|
|
19
|
+
"es",
|
|
19
20
|
"index.js",
|
|
20
21
|
"matchPath.js",
|
|
21
22
|
"withRouter.js",
|
|
22
|
-
"es",
|
|
23
23
|
"umd"
|
|
24
24
|
],
|
|
25
25
|
"main": "index.js",
|
|
@@ -27,52 +27,47 @@
|
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "node ./tools/build.js",
|
|
29
29
|
"watch": "babel ./modules -d . --ignore __tests__ --watch",
|
|
30
|
-
"
|
|
30
|
+
"prepublishOnly": "node ./tools/build.js",
|
|
31
31
|
"clean": "git clean -fdX .",
|
|
32
32
|
"lint": "eslint modules",
|
|
33
|
-
"test": "
|
|
33
|
+
"test": "jest"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"react": "
|
|
36
|
+
"react": ">=15"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"history": "^4.
|
|
40
|
-
"hoist-non-react-statics": "^
|
|
39
|
+
"history": "^4.7.2",
|
|
40
|
+
"hoist-non-react-statics": "^2.3.0",
|
|
41
41
|
"invariant": "^2.2.2",
|
|
42
42
|
"loose-envify": "^1.3.1",
|
|
43
|
-
"path-to-regexp": "^1.
|
|
43
|
+
"path-to-regexp": "^1.7.0",
|
|
44
44
|
"prop-types": "^15.5.4",
|
|
45
45
|
"warning": "^3.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"babel-cli": "^6.
|
|
49
|
-
"babel-eslint": "^
|
|
50
|
-
"babel-loader": "^6.2.10",
|
|
48
|
+
"babel-cli": "^6.26.0",
|
|
49
|
+
"babel-eslint": "^7.0.4",
|
|
51
50
|
"babel-plugin-dev-expression": "^0.2.1",
|
|
52
|
-
"babel-plugin-
|
|
51
|
+
"babel-plugin-external-helpers": "^6.22.0",
|
|
52
|
+
"babel-plugin-transform-react-remove-prop-types": "^0.4.8",
|
|
53
53
|
"babel-preset-es2015": "^6.14.0",
|
|
54
54
|
"babel-preset-react": "^6.5.0",
|
|
55
55
|
"babel-preset-stage-1": "^6.5.0",
|
|
56
|
-
"eslint": "^
|
|
56
|
+
"eslint": "^4.5.0",
|
|
57
57
|
"eslint-plugin-import": "^2.2.0",
|
|
58
|
-
"eslint-plugin-react": "^
|
|
59
|
-
"expect": "^1.20.1",
|
|
58
|
+
"eslint-plugin-react": "^7.3.0",
|
|
60
59
|
"gzip-size": "^3.0.0",
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"karma-browserstack-launcher": "^1.0.1",
|
|
64
|
-
"karma-chrome-launcher": "^1.0.1",
|
|
65
|
-
"karma-mocha": "^1.0.1",
|
|
66
|
-
"karma-mocha-reporter": "^2.0.4",
|
|
67
|
-
"karma-sourcemap-loader": "^0.3.7",
|
|
68
|
-
"karma-webpack": "^1.7.0",
|
|
69
|
-
"mocha": "^2.5.3",
|
|
70
|
-
"pretty-bytes": "^3.0.1",
|
|
60
|
+
"jest": "^20.0.4",
|
|
61
|
+
"pretty-bytes": "^4.0.2",
|
|
71
62
|
"react": "^15.4.2",
|
|
72
63
|
"react-addons-test-utils": "^15.4.2",
|
|
73
64
|
"react-dom": "^15.3.0",
|
|
74
|
-
"
|
|
75
|
-
"
|
|
65
|
+
"rollup": "^0.48.2",
|
|
66
|
+
"rollup-plugin-babel": "^3.0.2",
|
|
67
|
+
"rollup-plugin-commonjs": "^8.2.0",
|
|
68
|
+
"rollup-plugin-node-resolve": "^3.0.0",
|
|
69
|
+
"rollup-plugin-replace": "^1.1.1",
|
|
70
|
+
"rollup-plugin-uglify": "^2.0.1"
|
|
76
71
|
},
|
|
77
72
|
"browserify": {
|
|
78
73
|
"transform": [
|