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/es/Route.js CHANGED
@@ -7,9 +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 React, { PropTypes } from 'react';
10
+ import invariant from 'invariant';
11
+ import React from 'react';
12
+ import PropTypes from 'prop-types';
11
13
  import matchPath from './matchPath';
12
14
 
15
+ var isEmptyChildren = function isEmptyChildren(children) {
16
+ return React.Children.count(children) === 0;
17
+ };
18
+
13
19
  /**
14
20
  * The public API for matching a single path and rendering.
15
21
  */
@@ -32,8 +38,6 @@ var Route = function (_React$Component) {
32
38
  }
33
39
 
34
40
  Route.prototype.getChildContext = function getChildContext() {
35
- var router = this.context.router;
36
-
37
41
  return {
38
42
  router: _extends({}, this.context.router, {
39
43
  route: {
@@ -44,33 +48,31 @@ var Route = function (_React$Component) {
44
48
  };
45
49
  };
46
50
 
47
- Route.prototype.computeMatch = function computeMatch(_ref, _ref2) {
51
+ Route.prototype.computeMatch = function computeMatch(_ref, router) {
48
52
  var computedMatch = _ref.computedMatch,
49
53
  location = _ref.location,
50
54
  path = _ref.path,
51
55
  strict = _ref.strict,
52
- exact = _ref.exact;
53
- var route = _ref2.route;
56
+ exact = _ref.exact,
57
+ sensitive = _ref.sensitive;
54
58
 
55
59
  if (computedMatch) return computedMatch; // <Switch> already computed the match for us
56
60
 
61
+ invariant(router, 'You should not use <Route> or withRouter() outside a <Router>');
62
+
63
+ var route = router.route;
64
+
57
65
  var pathname = (location || route.location).pathname;
58
66
 
59
- 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;
60
68
  };
61
69
 
62
70
  Route.prototype.componentWillMount = function componentWillMount() {
63
- var _props = this.props,
64
- component = _props.component,
65
- render = _props.render,
66
- children = _props.children;
67
-
68
-
69
- 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');
70
72
 
71
- 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');
72
74
 
73
- 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');
74
76
  };
75
77
 
76
78
  Route.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextContext) {
@@ -85,10 +87,10 @@ var Route = function (_React$Component) {
85
87
 
86
88
  Route.prototype.render = function render() {
87
89
  var match = this.state.match;
88
- var _props2 = this.props,
89
- children = _props2.children,
90
- component = _props2.component,
91
- render = _props2.render;
90
+ var _props = this.props,
91
+ children = _props.children,
92
+ component = _props.component,
93
+ render = _props.render;
92
94
  var _context$router = this.context.router,
93
95
  history = _context$router.history,
94
96
  route = _context$router.route,
@@ -100,8 +102,7 @@ var Route = function (_React$Component) {
100
102
  return component ? // component prop gets first priority, only called if there's a match
101
103
  match ? React.createElement(component, props) : null : render ? // render prop is next, only called if there's a match
102
104
  match ? render(props) : null : children ? // children come last, always called
103
- typeof children === 'function' ? children(props) : !Array.isArray(children) || children.length ? // Preact defaults to empty children array
104
- React.Children.only(children) : null : null;
105
+ typeof children === 'function' ? children(props) : !isEmptyChildren(children) ? React.Children.only(children) : null : null;
105
106
  };
106
107
 
107
108
  return Route;
@@ -112,6 +113,7 @@ Route.propTypes = {
112
113
  path: PropTypes.string,
113
114
  exact: PropTypes.bool,
114
115
  strict: PropTypes.bool,
116
+ sensitive: PropTypes.bool,
115
117
  component: PropTypes.func,
116
118
  render: PropTypes.func,
117
119
  children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
package/es/Router.js CHANGED
@@ -8,7 +8,8 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
8
8
 
9
9
  import warning from 'warning';
10
10
  import invariant from 'invariant';
11
- import React, { PropTypes } from 'react';
11
+ import React from 'react';
12
+ import PropTypes from 'prop-types';
12
13
 
13
14
  /**
14
15
  * The public API for putting history on context.
@@ -8,8 +8,10 @@ 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
- import React, { PropTypes } from 'react';
13
+ import React from 'react';
14
+ import PropTypes from 'prop-types';
13
15
  import { addLeadingSlash, createPath, parsePath } from 'history/PathUtils';
14
16
  import Router from './Router';
15
17
 
@@ -117,6 +119,10 @@ var StaticRouter = function (_React$Component) {
117
119
  };
118
120
  };
119
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
+
120
126
  StaticRouter.prototype.render = function render() {
121
127
  var _props = this.props,
122
128
  basename = _props.basename,
package/es/Switch.js CHANGED
@@ -4,8 +4,10 @@ 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';
8
9
  import warning from 'warning';
10
+ import invariant from 'invariant';
9
11
  import matchPath from './matchPath';
10
12
 
11
13
  /**
@@ -21,6 +23,10 @@ var Switch = function (_React$Component) {
21
23
  return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
22
24
  }
23
25
 
26
+ Switch.prototype.componentWillMount = function componentWillMount() {
27
+ invariant(this.context.router, 'You should not use <Switch> outside a <Router>');
28
+ };
29
+
24
30
  Switch.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
25
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.');
26
32
 
@@ -36,17 +42,20 @@ var Switch = function (_React$Component) {
36
42
  var match = void 0,
37
43
  child = void 0;
38
44
  React.Children.forEach(children, function (element) {
45
+ if (!React.isValidElement(element)) return;
46
+
39
47
  var _element$props = element.props,
40
48
  pathProp = _element$props.path,
41
49
  exact = _element$props.exact,
42
50
  strict = _element$props.strict,
51
+ sensitive = _element$props.sensitive,
43
52
  from = _element$props.from;
44
53
 
45
54
  var path = pathProp || from;
46
55
 
47
56
  if (match == null) {
48
57
  child = element;
49
- 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;
50
59
  }
51
60
  });
52
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/es/withRouter.js CHANGED
@@ -1,6 +1,10 @@
1
1
  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; };
2
2
 
3
+ function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
4
+
3
5
  import React from 'react';
6
+ import PropTypes from 'prop-types';
7
+ import hoistStatics from 'hoist-non-react-statics';
4
8
  import Route from './Route';
5
9
 
6
10
  /**
@@ -8,14 +12,21 @@ import Route from './Route';
8
12
  */
9
13
  var withRouter = function withRouter(Component) {
10
14
  var C = function C(props) {
15
+ var wrappedComponentRef = props.wrappedComponentRef,
16
+ remainingProps = _objectWithoutProperties(props, ['wrappedComponentRef']);
17
+
11
18
  return React.createElement(Route, { render: function render(routeComponentProps) {
12
- return React.createElement(Component, _extends({}, props, routeComponentProps));
19
+ return React.createElement(Component, _extends({}, remainingProps, routeComponentProps, { ref: wrappedComponentRef }));
13
20
  } });
14
21
  };
15
22
 
16
23
  C.displayName = 'withRouter(' + (Component.displayName || Component.name) + ')';
24
+ C.WrappedComponent = Component;
25
+ C.propTypes = {
26
+ wrappedComponentRef: PropTypes.func
27
+ };
17
28
 
18
- return C;
29
+ return hoistStatics(C, Component);
19
30
  };
20
31
 
21
32
  export default withRouter;
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.0.0",
3
+ "version": "4.2.0",
4
4
  "description": "Declarative routing for React",
5
5
  "repository": "ReactTraining/react-router",
6
6
  "license": "MIT",
@@ -16,11 +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
- "README.md",
23
- "es",
24
23
  "umd"
25
24
  ],
26
25
  "main": "index.js",
@@ -28,51 +27,47 @@
28
27
  "scripts": {
29
28
  "build": "node ./tools/build.js",
30
29
  "watch": "babel ./modules -d . --ignore __tests__ --watch",
31
- "prepublish": "node ./tools/build.js",
32
- "clean": "git clean -e '!node_modules' -fdX .",
30
+ "prepublishOnly": "node ./tools/build.js",
31
+ "clean": "git clean -fdX .",
33
32
  "lint": "eslint modules",
34
- "test": "karma start --single-run"
33
+ "test": "jest"
35
34
  },
36
35
  "peerDependencies": {
37
- "react": "^15"
36
+ "react": ">=15"
38
37
  },
39
38
  "dependencies": {
40
- "history": "^4.6.0",
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.5.3",
43
+ "path-to-regexp": "^1.7.0",
44
+ "prop-types": "^15.5.4",
44
45
  "warning": "^3.0.0"
45
46
  },
46
47
  "devDependencies": {
47
- "babel-cli": "^6.18.0",
48
- "babel-eslint": "^6.0.4",
49
- "babel-loader": "^6.2.10",
48
+ "babel-cli": "^6.26.0",
49
+ "babel-eslint": "^7.0.4",
50
50
  "babel-plugin-dev-expression": "^0.2.1",
51
- "babel-plugin-transform-react-remove-prop-types": "^0.2.11",
51
+ "babel-plugin-external-helpers": "^6.22.0",
52
+ "babel-plugin-transform-react-remove-prop-types": "^0.4.8",
52
53
  "babel-preset-es2015": "^6.14.0",
53
54
  "babel-preset-react": "^6.5.0",
54
55
  "babel-preset-stage-1": "^6.5.0",
55
- "eslint": "^2.13.1",
56
- "eslint-plugin-import": "^1.15.0",
57
- "eslint-plugin-react": "^5.2.2",
58
- "expect": "^1.20.1",
56
+ "eslint": "^4.5.0",
57
+ "eslint-plugin-import": "^2.2.0",
58
+ "eslint-plugin-react": "^7.3.0",
59
59
  "gzip-size": "^3.0.0",
60
- "in-publish": "^2.0.0",
61
- "karma": "^0.13.22",
62
- "karma-browserstack-launcher": "^1.0.1",
63
- "karma-chrome-launcher": "^1.0.1",
64
- "karma-mocha": "^1.0.1",
65
- "karma-mocha-reporter": "^2.0.4",
66
- "karma-sourcemap-loader": "^0.3.7",
67
- "karma-webpack": "^1.7.0",
68
- "mocha": "^2.5.3",
69
- "pretty-bytes": "^3.0.1",
60
+ "jest": "^20.0.4",
61
+ "pretty-bytes": "^4.0.2",
70
62
  "react": "^15.4.2",
71
63
  "react-addons-test-utils": "^15.4.2",
72
64
  "react-dom": "^15.3.0",
73
- "readline-sync": "^1.4.4",
74
- "webpack": "^1.13.1",
75
- "webpack-dev-server": "^1.14.1"
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": [