react-router 3.0.1 → 3.0.5
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/CHANGES.md +38 -0
- package/README.md +6 -1
- package/docs/API.md +6 -3
- package/docs/guides/ConfirmingNavigation.md +3 -0
- package/docs/guides/Histories.md +4 -4
- package/docs/guides/RouteMatching.md +1 -1
- package/es/ContextUtils.js +1 -1
- package/es/IndexLink.js +3 -1
- package/es/IndexRedirect.js +3 -8
- package/es/IndexRoute.js +3 -6
- package/es/InternalPropTypes.js +1 -10
- package/es/Link.js +3 -18
- package/es/PropTypes.js +1 -7
- package/es/Redirect.js +3 -8
- package/es/Route.js +3 -8
- package/es/Router.js +18 -20
- package/es/RouterContext.js +3 -8
- package/es/TransitionUtils.js +113 -105
- package/es/computeChangedRoutes.js +19 -21
- package/es/createRouterHistory.js +1 -1
- package/es/createTransitionManager.js +8 -1
- package/es/matchRoutes.js +23 -31
- package/es/withRouter.js +2 -1
- package/lib/ContextUtils.js +8 -4
- package/lib/IndexLink.js +6 -1
- package/lib/IndexRedirect.js +8 -12
- package/lib/IndexRoute.js +7 -9
- package/lib/InternalPropTypes.js +12 -19
- package/lib/Link.js +13 -24
- package/lib/PropTypes.js +15 -19
- package/lib/Redirect.js +10 -14
- package/lib/Route.js +8 -12
- package/lib/Router.js +22 -20
- package/lib/RouterContext.js +14 -15
- package/lib/TransitionUtils.js +112 -105
- package/lib/computeChangedRoutes.js +19 -21
- package/lib/createRouterHistory.js +6 -6
- package/lib/createTransitionManager.js +12 -3
- package/lib/matchRoutes.js +23 -31
- package/lib/withRouter.js +5 -1
- package/package.json +19 -17
- package/umd/ReactRouter.js +2315 -651
- package/umd/ReactRouter.min.js +6 -2
package/lib/PropTypes.js
CHANGED
|
@@ -3,26 +3,22 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.locationShape = exports.routerShape = undefined;
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _propTypes = require('prop-types');
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
goBack: func.isRequired,
|
|
17
|
-
goForward: func.isRequired,
|
|
18
|
-
setRouteLeaveHook: func.isRequired,
|
|
19
|
-
isActive: func.isRequired
|
|
8
|
+
var routerShape = exports.routerShape = (0, _propTypes.shape)({
|
|
9
|
+
push: _propTypes.func.isRequired,
|
|
10
|
+
replace: _propTypes.func.isRequired,
|
|
11
|
+
go: _propTypes.func.isRequired,
|
|
12
|
+
goBack: _propTypes.func.isRequired,
|
|
13
|
+
goForward: _propTypes.func.isRequired,
|
|
14
|
+
setRouteLeaveHook: _propTypes.func.isRequired,
|
|
15
|
+
isActive: _propTypes.func.isRequired
|
|
20
16
|
});
|
|
21
17
|
|
|
22
|
-
var locationShape = exports.locationShape = shape({
|
|
23
|
-
pathname: string.isRequired,
|
|
24
|
-
search: string.isRequired,
|
|
25
|
-
state: object,
|
|
26
|
-
action: string.isRequired,
|
|
27
|
-
key: string
|
|
18
|
+
var locationShape = exports.locationShape = (0, _propTypes.shape)({
|
|
19
|
+
pathname: _propTypes.string.isRequired,
|
|
20
|
+
search: _propTypes.string.isRequired,
|
|
21
|
+
state: _propTypes.object,
|
|
22
|
+
action: _propTypes.string.isRequired,
|
|
23
|
+
key: _propTypes.string
|
|
28
24
|
});
|
package/lib/Redirect.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _createReactClass = require('create-react-class');
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _createReactClass2 = _interopRequireDefault(_createReactClass);
|
|
8
|
+
|
|
9
|
+
var _propTypes = require('prop-types');
|
|
8
10
|
|
|
9
11
|
var _invariant = require('invariant');
|
|
10
12
|
|
|
@@ -18,10 +20,6 @@ var _InternalPropTypes = require('./InternalPropTypes');
|
|
|
18
20
|
|
|
19
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
22
|
|
|
21
|
-
var _React$PropTypes = _react2.default.PropTypes,
|
|
22
|
-
string = _React$PropTypes.string,
|
|
23
|
-
object = _React$PropTypes.object;
|
|
24
|
-
|
|
25
23
|
/**
|
|
26
24
|
* A <Redirect> is used to declare another URL path a client should
|
|
27
25
|
* be sent to when they request a given URL.
|
|
@@ -30,11 +28,9 @@ var _React$PropTypes = _react2.default.PropTypes,
|
|
|
30
28
|
* and are traversed in the same manner.
|
|
31
29
|
*/
|
|
32
30
|
/* eslint-disable react/require-render-return */
|
|
33
|
-
|
|
34
|
-
var Redirect = _react2.default.createClass({
|
|
31
|
+
var Redirect = (0, _createReactClass2.default)({
|
|
35
32
|
displayName: 'Redirect',
|
|
36
33
|
|
|
37
|
-
|
|
38
34
|
statics: {
|
|
39
35
|
createRouteFromReactElement: function createRouteFromReactElement(element) {
|
|
40
36
|
var route = (0, _RouteUtils.createRouteFromReactElement)(element);
|
|
@@ -84,11 +80,11 @@ var Redirect = _react2.default.createClass({
|
|
|
84
80
|
},
|
|
85
81
|
|
|
86
82
|
propTypes: {
|
|
87
|
-
path: string,
|
|
88
|
-
from: string, // Alias for path
|
|
89
|
-
to: string.isRequired,
|
|
90
|
-
query: object,
|
|
91
|
-
state: object,
|
|
83
|
+
path: _propTypes.string,
|
|
84
|
+
from: _propTypes.string, // Alias for path
|
|
85
|
+
to: _propTypes.string.isRequired,
|
|
86
|
+
query: _propTypes.object,
|
|
87
|
+
state: _propTypes.object,
|
|
92
88
|
onEnter: _InternalPropTypes.falsy,
|
|
93
89
|
children: _InternalPropTypes.falsy
|
|
94
90
|
},
|
package/lib/Route.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _createReactClass = require('create-react-class');
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _createReactClass2 = _interopRequireDefault(_createReactClass);
|
|
8
|
+
|
|
9
|
+
var _propTypes = require('prop-types');
|
|
8
10
|
|
|
9
11
|
var _invariant = require('invariant');
|
|
10
12
|
|
|
@@ -16,10 +18,6 @@ var _InternalPropTypes = require('./InternalPropTypes');
|
|
|
16
18
|
|
|
17
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
20
|
|
|
19
|
-
var _React$PropTypes = _react2.default.PropTypes,
|
|
20
|
-
string = _React$PropTypes.string,
|
|
21
|
-
func = _React$PropTypes.func;
|
|
22
|
-
|
|
23
21
|
/**
|
|
24
22
|
* A <Route> is used to declare which components are rendered to the
|
|
25
23
|
* page when the URL matches a given pattern.
|
|
@@ -31,21 +29,19 @@ var _React$PropTypes = _react2.default.PropTypes,
|
|
|
31
29
|
* rendered into the DOM, nested in the same order as in the tree.
|
|
32
30
|
*/
|
|
33
31
|
/* eslint-disable react/require-render-return */
|
|
34
|
-
|
|
35
|
-
var Route = _react2.default.createClass({
|
|
32
|
+
var Route = (0, _createReactClass2.default)({
|
|
36
33
|
displayName: 'Route',
|
|
37
34
|
|
|
38
|
-
|
|
39
35
|
statics: {
|
|
40
36
|
createRouteFromReactElement: _RouteUtils.createRouteFromReactElement
|
|
41
37
|
},
|
|
42
38
|
|
|
43
39
|
propTypes: {
|
|
44
|
-
path: string,
|
|
40
|
+
path: _propTypes.string,
|
|
45
41
|
component: _InternalPropTypes.component,
|
|
46
42
|
components: _InternalPropTypes.components,
|
|
47
|
-
getComponent: func,
|
|
48
|
-
getComponents: func
|
|
43
|
+
getComponent: _propTypes.func,
|
|
44
|
+
getComponents: _propTypes.func
|
|
49
45
|
},
|
|
50
46
|
|
|
51
47
|
/* istanbul ignore next: sanity check */
|
package/lib/Router.js
CHANGED
|
@@ -12,6 +12,12 @@ var _react = require('react');
|
|
|
12
12
|
|
|
13
13
|
var _react2 = _interopRequireDefault(_react);
|
|
14
14
|
|
|
15
|
+
var _createReactClass = require('create-react-class');
|
|
16
|
+
|
|
17
|
+
var _createReactClass2 = _interopRequireDefault(_createReactClass);
|
|
18
|
+
|
|
19
|
+
var _propTypes = require('prop-types');
|
|
20
|
+
|
|
15
21
|
var _createTransitionManager2 = require('./createTransitionManager');
|
|
16
22
|
|
|
17
23
|
var _createTransitionManager3 = _interopRequireDefault(_createTransitionManager2);
|
|
@@ -34,32 +40,28 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
34
40
|
|
|
35
41
|
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; }
|
|
36
42
|
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
var propTypes = {
|
|
44
|
+
history: _propTypes.object,
|
|
45
|
+
children: _InternalPropTypes.routes,
|
|
46
|
+
routes: _InternalPropTypes.routes, // alias for children
|
|
47
|
+
render: _propTypes.func,
|
|
48
|
+
createElement: _propTypes.func,
|
|
49
|
+
onError: _propTypes.func,
|
|
50
|
+
onUpdate: _propTypes.func,
|
|
51
|
+
|
|
52
|
+
// PRIVATE: For client-side rehydration of server match.
|
|
53
|
+
matchContext: _propTypes.object
|
|
54
|
+
};
|
|
40
55
|
|
|
41
56
|
/**
|
|
42
57
|
* A <Router> is a high-level API for automatically setting up
|
|
43
58
|
* a router that renders a <RouterContext> with all the props
|
|
44
59
|
* it needs each time the URL changes.
|
|
45
60
|
*/
|
|
46
|
-
|
|
47
|
-
var Router = _react2.default.createClass({
|
|
61
|
+
var Router = (0, _createReactClass2.default)({
|
|
48
62
|
displayName: 'Router',
|
|
49
63
|
|
|
50
|
-
|
|
51
|
-
propTypes: {
|
|
52
|
-
history: object,
|
|
53
|
-
children: _InternalPropTypes.routes,
|
|
54
|
-
routes: _InternalPropTypes.routes, // alias for children
|
|
55
|
-
render: func,
|
|
56
|
-
createElement: func,
|
|
57
|
-
onError: func,
|
|
58
|
-
onUpdate: func,
|
|
59
|
-
|
|
60
|
-
// PRIVATE: For client-side rehydration of server match.
|
|
61
|
-
matchContext: object
|
|
62
|
-
},
|
|
64
|
+
propTypes: propTypes,
|
|
63
65
|
|
|
64
66
|
getDefaultProps: function getDefaultProps() {
|
|
65
67
|
return {
|
|
@@ -108,7 +110,7 @@ var Router = _react2.default.createClass({
|
|
|
108
110
|
children = _props.children;
|
|
109
111
|
|
|
110
112
|
|
|
111
|
-
!history.getCurrentLocation ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'You have provided a history object created with history
|
|
113
|
+
!history.getCurrentLocation ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'You have provided a history object created with history v4.x or v2.x ' + 'and earlier. This version of React Router is only compatible with v3 ' + 'history objects. Please change to history v3.x.') : (0, _invariant2.default)(false) : void 0;
|
|
112
114
|
|
|
113
115
|
return (0, _createTransitionManager3.default)(history, (0, _RouteUtils.createRoutes)(routes || children));
|
|
114
116
|
},
|
|
@@ -156,7 +158,7 @@ var Router = _react2.default.createClass({
|
|
|
156
158
|
|
|
157
159
|
// Only forward non-Router-specific props to routing context, as those are
|
|
158
160
|
// the only ones that might be custom routing context props.
|
|
159
|
-
Object.keys(
|
|
161
|
+
Object.keys(propTypes).forEach(function (propType) {
|
|
160
162
|
return delete props[propType];
|
|
161
163
|
});
|
|
162
164
|
|
package/lib/RouterContext.js
CHANGED
|
@@ -14,6 +14,12 @@ var _react = require('react');
|
|
|
14
14
|
|
|
15
15
|
var _react2 = _interopRequireDefault(_react);
|
|
16
16
|
|
|
17
|
+
var _createReactClass = require('create-react-class');
|
|
18
|
+
|
|
19
|
+
var _createReactClass2 = _interopRequireDefault(_createReactClass);
|
|
20
|
+
|
|
21
|
+
var _propTypes = require('prop-types');
|
|
22
|
+
|
|
17
23
|
var _getRouteParams = require('./getRouteParams');
|
|
18
24
|
|
|
19
25
|
var _getRouteParams2 = _interopRequireDefault(_getRouteParams);
|
|
@@ -24,29 +30,22 @@ var _RouteUtils = require('./RouteUtils');
|
|
|
24
30
|
|
|
25
31
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
26
32
|
|
|
27
|
-
var _React$PropTypes = _react2.default.PropTypes,
|
|
28
|
-
array = _React$PropTypes.array,
|
|
29
|
-
func = _React$PropTypes.func,
|
|
30
|
-
object = _React$PropTypes.object;
|
|
31
|
-
|
|
32
33
|
/**
|
|
33
34
|
* A <RouterContext> renders the component tree for a given router state
|
|
34
35
|
* and sets the history object and the current location in context.
|
|
35
36
|
*/
|
|
36
|
-
|
|
37
|
-
var RouterContext = _react2.default.createClass({
|
|
37
|
+
var RouterContext = (0, _createReactClass2.default)({
|
|
38
38
|
displayName: 'RouterContext',
|
|
39
39
|
|
|
40
|
-
|
|
41
40
|
mixins: [(0, _ContextUtils.ContextProvider)('router')],
|
|
42
41
|
|
|
43
42
|
propTypes: {
|
|
44
|
-
router: object.isRequired,
|
|
45
|
-
location: object.isRequired,
|
|
46
|
-
routes: array.isRequired,
|
|
47
|
-
params: object.isRequired,
|
|
48
|
-
components: array.isRequired,
|
|
49
|
-
createElement: func.isRequired
|
|
43
|
+
router: _propTypes.object.isRequired,
|
|
44
|
+
location: _propTypes.object.isRequired,
|
|
45
|
+
routes: _propTypes.array.isRequired,
|
|
46
|
+
params: _propTypes.object.isRequired,
|
|
47
|
+
components: _propTypes.array.isRequired,
|
|
48
|
+
createElement: _propTypes.func.isRequired
|
|
50
49
|
},
|
|
51
50
|
|
|
52
51
|
getDefaultProps: function getDefaultProps() {
|
|
@@ -57,7 +56,7 @@ var RouterContext = _react2.default.createClass({
|
|
|
57
56
|
|
|
58
57
|
|
|
59
58
|
childContextTypes: {
|
|
60
|
-
router: object.isRequired
|
|
59
|
+
router: _propTypes.object.isRequired
|
|
61
60
|
},
|
|
62
61
|
|
|
63
62
|
getChildContext: function getChildContext() {
|
package/lib/TransitionUtils.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.
|
|
5
|
-
exports.runChangeHooks = runChangeHooks;
|
|
6
|
-
exports.runLeaveHooks = runLeaveHooks;
|
|
4
|
+
exports.default = getTransitionUtils;
|
|
7
5
|
|
|
8
6
|
var _AsyncUtils = require('./AsyncUtils');
|
|
9
7
|
|
|
@@ -35,121 +33,130 @@ var PendingHooks = function PendingHooks() {
|
|
|
35
33
|
};
|
|
36
34
|
};
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
var
|
|
36
|
+
function getTransitionUtils() {
|
|
37
|
+
var enterHooks = new PendingHooks();
|
|
38
|
+
var changeHooks = new PendingHooks();
|
|
40
39
|
|
|
41
|
-
function createTransitionHook(hook, route, asyncArity, pendingHooks) {
|
|
42
|
-
|
|
40
|
+
function createTransitionHook(hook, route, asyncArity, pendingHooks) {
|
|
41
|
+
var isSync = hook.length < asyncArity;
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
var transitionHook = function transitionHook() {
|
|
44
|
+
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
45
|
+
args[_key] = arguments[_key];
|
|
46
|
+
}
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
hook.apply(route, args);
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
if (isSync) {
|
|
51
|
+
var callback = args[args.length - 1];
|
|
52
|
+
// Assume hook executes synchronously and
|
|
53
|
+
// automatically call the callback.
|
|
54
|
+
callback();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
pendingHooks.add(transitionHook);
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
}
|
|
60
|
+
return transitionHook;
|
|
61
|
+
}
|
|
63
62
|
|
|
64
|
-
function getEnterHooks(routes) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
63
|
+
function getEnterHooks(routes) {
|
|
64
|
+
return routes.reduce(function (hooks, route) {
|
|
65
|
+
if (route.onEnter) hooks.push(createTransitionHook(route.onEnter, route, 3, enterHooks));
|
|
66
|
+
return hooks;
|
|
67
|
+
}, []);
|
|
68
|
+
}
|
|
70
69
|
|
|
71
|
-
function getChangeHooks(routes) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
70
|
+
function getChangeHooks(routes) {
|
|
71
|
+
return routes.reduce(function (hooks, route) {
|
|
72
|
+
if (route.onChange) hooks.push(createTransitionHook(route.onChange, route, 4, changeHooks));
|
|
73
|
+
return hooks;
|
|
74
|
+
}, []);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function runTransitionHooks(length, iter, callback) {
|
|
78
|
+
if (!length) {
|
|
79
|
+
callback();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
77
82
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
var redirectInfo = void 0;
|
|
84
|
+
function replace(location) {
|
|
85
|
+
redirectInfo = location;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
(0, _AsyncUtils.loopAsync)(length, function (index, next, done) {
|
|
89
|
+
iter(index, replace, function (error) {
|
|
90
|
+
if (error || redirectInfo) {
|
|
91
|
+
done(error, redirectInfo); // No need to continue.
|
|
92
|
+
} else {
|
|
93
|
+
next();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}, callback);
|
|
82
97
|
}
|
|
83
98
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Runs all onEnter hooks in the given array of routes in order
|
|
101
|
+
* with onEnter(nextState, replace, callback) and calls
|
|
102
|
+
* callback(error, redirectInfo) when finished. The first hook
|
|
103
|
+
* to use replace short-circuits the loop.
|
|
104
|
+
*
|
|
105
|
+
* If a hook needs to run asynchronously, it may use the callback
|
|
106
|
+
* function. However, doing so will cause the transition to pause,
|
|
107
|
+
* which could lead to a non-responsive UI if the hook is slow.
|
|
108
|
+
*/
|
|
109
|
+
function runEnterHooks(routes, nextState, callback) {
|
|
110
|
+
enterHooks.clear();
|
|
111
|
+
var hooks = getEnterHooks(routes);
|
|
112
|
+
return runTransitionHooks(hooks.length, function (index, replace, next) {
|
|
113
|
+
var wrappedNext = function wrappedNext() {
|
|
114
|
+
if (enterHooks.has(hooks[index])) {
|
|
115
|
+
next.apply(undefined, arguments);
|
|
116
|
+
enterHooks.remove(hooks[index]);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
hooks[index](nextState, replace, wrappedNext);
|
|
120
|
+
}, callback);
|
|
87
121
|
}
|
|
88
122
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Runs all onChange hooks in the given array of routes in order
|
|
125
|
+
* with onChange(prevState, nextState, replace, callback) and calls
|
|
126
|
+
* callback(error, redirectInfo) when finished. The first hook
|
|
127
|
+
* to use replace short-circuits the loop.
|
|
128
|
+
*
|
|
129
|
+
* If a hook needs to run asynchronously, it may use the callback
|
|
130
|
+
* function. However, doing so will cause the transition to pause,
|
|
131
|
+
* which could lead to a non-responsive UI if the hook is slow.
|
|
132
|
+
*/
|
|
133
|
+
function runChangeHooks(routes, state, nextState, callback) {
|
|
134
|
+
changeHooks.clear();
|
|
135
|
+
var hooks = getChangeHooks(routes);
|
|
136
|
+
return runTransitionHooks(hooks.length, function (index, replace, next) {
|
|
137
|
+
var wrappedNext = function wrappedNext() {
|
|
138
|
+
if (changeHooks.has(hooks[index])) {
|
|
139
|
+
next.apply(undefined, arguments);
|
|
140
|
+
changeHooks.remove(hooks[index]);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
hooks[index](state, nextState, replace, wrappedNext);
|
|
144
|
+
}, callback);
|
|
145
|
+
}
|
|
99
146
|
|
|
100
|
-
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
* which could lead to a non-responsive UI if the hook is slow.
|
|
109
|
-
*/
|
|
110
|
-
function runEnterHooks(routes, nextState, callback) {
|
|
111
|
-
enterHooks.clear();
|
|
112
|
-
var hooks = getEnterHooks(routes);
|
|
113
|
-
return runTransitionHooks(hooks.length, function (index, replace, next) {
|
|
114
|
-
var wrappedNext = function wrappedNext() {
|
|
115
|
-
if (enterHooks.has(hooks[index])) {
|
|
116
|
-
next.apply(undefined, arguments);
|
|
117
|
-
enterHooks.remove(hooks[index]);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
hooks[index](nextState, replace, wrappedNext);
|
|
121
|
-
}, callback);
|
|
122
|
-
}
|
|
147
|
+
/**
|
|
148
|
+
* Runs all onLeave hooks in the given array of routes in order.
|
|
149
|
+
*/
|
|
150
|
+
function runLeaveHooks(routes, prevState) {
|
|
151
|
+
for (var i = 0, len = routes.length; i < len; ++i) {
|
|
152
|
+
if (routes[i].onLeave) routes[i].onLeave.call(routes[i], prevState);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
123
155
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
* If a hook needs to run asynchronously, it may use the callback
|
|
131
|
-
* function. However, doing so will cause the transition to pause,
|
|
132
|
-
* which could lead to a non-responsive UI if the hook is slow.
|
|
133
|
-
*/
|
|
134
|
-
function runChangeHooks(routes, state, nextState, callback) {
|
|
135
|
-
changeHooks.clear();
|
|
136
|
-
var hooks = getChangeHooks(routes);
|
|
137
|
-
return runTransitionHooks(hooks.length, function (index, replace, next) {
|
|
138
|
-
var wrappedNext = function wrappedNext() {
|
|
139
|
-
if (changeHooks.has(hooks[index])) {
|
|
140
|
-
next.apply(undefined, arguments);
|
|
141
|
-
changeHooks.remove(hooks[index]);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
hooks[index](state, nextState, replace, wrappedNext);
|
|
145
|
-
}, callback);
|
|
156
|
+
return {
|
|
157
|
+
runEnterHooks: runEnterHooks,
|
|
158
|
+
runChangeHooks: runChangeHooks,
|
|
159
|
+
runLeaveHooks: runLeaveHooks
|
|
160
|
+
};
|
|
146
161
|
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Runs all onLeave hooks in the given array of routes in order.
|
|
150
|
-
*/
|
|
151
|
-
function runLeaveHooks(routes, prevState) {
|
|
152
|
-
for (var i = 0, len = routes.length; i < len; ++i) {
|
|
153
|
-
if (routes[i].onLeave) routes[i].onLeave.call(routes[i], prevState);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
162
|
+
module.exports = exports['default'];
|
|
@@ -35,31 +35,29 @@ function computeChangedRoutes(prevState, nextState) {
|
|
|
35
35
|
changeRoutes = void 0,
|
|
36
36
|
enterRoutes = void 0;
|
|
37
37
|
if (prevRoutes) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
38
|
+
var parentIsLeaving = false;
|
|
39
|
+
leaveRoutes = prevRoutes.filter(function (route) {
|
|
40
|
+
if (parentIsLeaving) {
|
|
41
|
+
return true;
|
|
42
|
+
} else {
|
|
43
|
+
var isLeaving = nextRoutes.indexOf(route) === -1 || routeParamsChanged(route, prevState, nextState);
|
|
44
|
+
if (isLeaving) parentIsLeaving = true;
|
|
45
|
+
return isLeaving;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
// onLeave hooks start at the leaf route.
|
|
50
|
+
leaveRoutes.reverse();
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
enterRoutes = [];
|
|
53
|
+
changeRoutes = [];
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
nextRoutes.forEach(function (route) {
|
|
56
|
+
var isNew = prevRoutes.indexOf(route) === -1;
|
|
57
|
+
var paramsChanged = leaveRoutes.indexOf(route) !== -1;
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
})();
|
|
59
|
+
if (isNew || paramsChanged) enterRoutes.push(route);else changeRoutes.push(route);
|
|
60
|
+
});
|
|
63
61
|
} else {
|
|
64
62
|
leaveRoutes = [];
|
|
65
63
|
changeRoutes = [];
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
|
|
5
|
-
exports.default = function (createHistory) {
|
|
6
|
-
var history = void 0;
|
|
7
|
-
if (canUseDOM) history = (0, _useRouterHistory2.default)(createHistory)();
|
|
8
|
-
return history;
|
|
9
|
-
};
|
|
4
|
+
exports.default = createRouterHistory;
|
|
10
5
|
|
|
11
6
|
var _useRouterHistory = require('./useRouterHistory');
|
|
12
7
|
|
|
@@ -16,4 +11,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
16
11
|
|
|
17
12
|
var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
18
13
|
|
|
14
|
+
function createRouterHistory(createHistory) {
|
|
15
|
+
var history = void 0;
|
|
16
|
+
if (canUseDOM) history = (0, _useRouterHistory2.default)(createHistory)();
|
|
17
|
+
return history;
|
|
18
|
+
}
|
|
19
19
|
module.exports = exports['default'];
|
|
@@ -16,6 +16,8 @@ var _computeChangedRoutes3 = _interopRequireDefault(_computeChangedRoutes2);
|
|
|
16
16
|
|
|
17
17
|
var _TransitionUtils = require('./TransitionUtils');
|
|
18
18
|
|
|
19
|
+
var _TransitionUtils2 = _interopRequireDefault(_TransitionUtils);
|
|
20
|
+
|
|
19
21
|
var _isActive2 = require('./isActive');
|
|
20
22
|
|
|
21
23
|
var _isActive3 = _interopRequireDefault(_isActive2);
|
|
@@ -39,8 +41,15 @@ function hasAnyProperties(object) {
|
|
|
39
41
|
function createTransitionManager(history, routes) {
|
|
40
42
|
var state = {};
|
|
41
43
|
|
|
44
|
+
var _getTransitionUtils = (0, _TransitionUtils2.default)(),
|
|
45
|
+
runEnterHooks = _getTransitionUtils.runEnterHooks,
|
|
46
|
+
runChangeHooks = _getTransitionUtils.runChangeHooks,
|
|
47
|
+
runLeaveHooks = _getTransitionUtils.runLeaveHooks;
|
|
48
|
+
|
|
42
49
|
// Signature should be (location, indexOnly), but needs to support (path,
|
|
43
50
|
// query, indexOnly)
|
|
51
|
+
|
|
52
|
+
|
|
44
53
|
function isActive(location, indexOnly) {
|
|
45
54
|
location = history.createLocation(location);
|
|
46
55
|
|
|
@@ -72,7 +81,7 @@ function createTransitionManager(history, routes) {
|
|
|
72
81
|
changeRoutes = _computeChangedRoutes.changeRoutes,
|
|
73
82
|
enterRoutes = _computeChangedRoutes.enterRoutes;
|
|
74
83
|
|
|
75
|
-
|
|
84
|
+
runLeaveHooks(leaveRoutes, state);
|
|
76
85
|
|
|
77
86
|
// Tear down confirmation hooks for left routes
|
|
78
87
|
leaveRoutes.filter(function (route) {
|
|
@@ -80,10 +89,10 @@ function createTransitionManager(history, routes) {
|
|
|
80
89
|
}).forEach(removeListenBeforeHooksForRoute);
|
|
81
90
|
|
|
82
91
|
// change and enter hooks are run in series
|
|
83
|
-
|
|
92
|
+
runChangeHooks(changeRoutes, state, nextState, function (error, redirectInfo) {
|
|
84
93
|
if (error || redirectInfo) return handleErrorOrRedirect(error, redirectInfo);
|
|
85
94
|
|
|
86
|
-
|
|
95
|
+
runEnterHooks(enterRoutes, nextState, finishEnterHooks);
|
|
87
96
|
});
|
|
88
97
|
|
|
89
98
|
function finishEnterHooks(error, redirectInfo) {
|