react-router 3.0.4 → 3.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/CHANGES.md +6 -0
- package/README.md +3 -3
- package/docs/API.md +15 -3
- package/docs/Glossary.md +13 -12
- package/docs/README.md +3 -1
- package/docs/guides/DynamicRouting.md +1 -1
- package/docs/guides/RouteConfiguration.md +1 -1
- package/docs/guides/Testing.md +2 -1
- package/es/IndexLink.js +2 -0
- package/es/IndexRedirect.js +1 -0
- package/es/IndexRoute.js +1 -0
- package/es/Link.js +1 -0
- package/es/Redirect.js +1 -0
- package/es/Route.js +1 -0
- package/es/Router.js +8 -8
- package/es/RouterContext.js +1 -0
- package/es/TransitionUtils.js +113 -105
- package/es/createTransitionManager.js +8 -1
- package/es/withRouter.js +2 -0
- package/lib/IndexLink.js +2 -0
- package/lib/IndexRedirect.js +1 -0
- package/lib/IndexRoute.js +1 -0
- package/lib/Link.js +1 -0
- package/lib/Redirect.js +1 -0
- package/lib/Route.js +1 -0
- package/lib/Router.js +8 -8
- package/lib/RouterContext.js +1 -0
- package/lib/TransitionUtils.js +112 -105
- package/lib/createTransitionManager.js +12 -3
- package/lib/withRouter.js +2 -0
- package/package.json +5 -5
- package/umd/ReactRouter.js +819 -592
- package/umd/ReactRouter.min.js +2 -2
package/CHANGES.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [v3.0.5](https://github.com/ReactTraining/react-router/compare/v3.0.4...v3.0.5)
|
|
2
|
+
> Apr 10, 2017
|
|
3
|
+
|
|
4
|
+
- Manually set displayName for components
|
|
5
|
+
- Async hooks could be removed during simultaneous server requests (#4941 by @s-yadav)
|
|
6
|
+
|
|
1
7
|
## [v3.0.4](https://github.com/ReactTraining/react-router/compare/v3.0.3...v3.0.4)
|
|
2
8
|
> Apr 9, 2017
|
|
3
9
|
|
package/README.md
CHANGED
|
@@ -9,11 +9,11 @@ React Router keeps your UI in sync with the URL. It has a simple API with powerf
|
|
|
9
9
|
[![Codecov][codecov-badge]][codecov]
|
|
10
10
|
[![Discord][discord-badge]][discord]
|
|
11
11
|
|
|
12
|
-
###
|
|
12
|
+
### 4.0 is here!
|
|
13
13
|
|
|
14
|
-
The next version of React Router (
|
|
14
|
+
The next version of React Router (4.0) has been released! Check out the `master` branch.
|
|
15
15
|
|
|
16
|
-
[
|
|
16
|
+
[4.0 Documentation](https://reacttraining.com/react-router/)
|
|
17
17
|
|
|
18
18
|
### Docs & Help
|
|
19
19
|
|
package/docs/API.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# API Reference
|
|
1
|
+
# React Router 3 API Reference
|
|
2
2
|
|
|
3
3
|
- [Components](#components)
|
|
4
4
|
- [`<Router>`](#router)
|
|
@@ -159,7 +159,19 @@ Given a route like `<Route path="/users/:userId" />`:
|
|
|
159
159
|
An `<IndexLink>` is like a [`<Link>`](#link), except it is only active when the current route is exactly the linked route. It is equivalent to `<Link>` with the `onlyActiveOnIndex` prop set.
|
|
160
160
|
|
|
161
161
|
### `withRouter(Component, [options])`
|
|
162
|
-
A HoC (higher-order component) that wraps another component to
|
|
162
|
+
A HoC (higher-order component) that wraps another component to enhance its props with router props.
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
withRouterProps = {
|
|
166
|
+
...componentProps,
|
|
167
|
+
router,
|
|
168
|
+
params,
|
|
169
|
+
location,
|
|
170
|
+
routes
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Pass in your component and it will return the wrapped component.
|
|
163
175
|
|
|
164
176
|
You can explicit specify `router` as a prop to the wrapper component to override the router object from context.
|
|
165
177
|
|
|
@@ -176,7 +188,7 @@ const myInstance = wrapperInstance.getWrappedInstance()
|
|
|
176
188
|
```
|
|
177
189
|
|
|
178
190
|
### `<RouterContext>`
|
|
179
|
-
A `<RouterContext>` renders the component tree for a given router state.
|
|
191
|
+
A `<RouterContext>` renders the component tree for a given router state. It's used by `<Router>` but also useful for server rendering and integrating in brownfield development.
|
|
180
192
|
|
|
181
193
|
It also provides a `router` object on [context](https://facebook.github.io/react/docs/context.html).
|
|
182
194
|
|
package/docs/Glossary.md
CHANGED
|
@@ -40,7 +40,7 @@ An *action* describes the type of change to a URL. Possible values are:
|
|
|
40
40
|
## Component
|
|
41
41
|
|
|
42
42
|
```js
|
|
43
|
-
type Component = ReactClass | string;
|
|
43
|
+
type Component = ReactClass<any> | string;
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
A *component* is a React component class or a string (e.g. "div"). Basically, it's anything that can be used as the first argument to [`React.createElement`](https://facebook.github.io/react/docs/top-level-api.html#react.createelement).
|
|
@@ -48,7 +48,8 @@ A *component* is a React component class or a string (e.g. "div"). Basically, it
|
|
|
48
48
|
## EnterHook
|
|
49
49
|
|
|
50
50
|
```js
|
|
51
|
-
type EnterHook = (nextState: RouterState, replace: RedirectFunction
|
|
51
|
+
type EnterHook = ((nextState: RouterState, replace: RedirectFunction) => any)
|
|
52
|
+
| ((nextState: RouterState, replace: RedirectFunction, callback: (error?: ?Error) => any) => any);
|
|
52
53
|
```
|
|
53
54
|
|
|
54
55
|
An *enter hook* is a user-defined function that is called when a route is about to be rendered. It receives the next [router state](#routerstate) as its first argument. The [`replace` function](#redirectfunction) may be used to trigger a transition to a different URL.
|
|
@@ -89,22 +90,22 @@ A *location* answers two important (philosophical) questions:
|
|
|
89
90
|
- Where am I?
|
|
90
91
|
- How did I get here?
|
|
91
92
|
|
|
92
|
-
New locations are typically created each time the URL changes. You can read more about locations in [the `history` docs](https://github.com/
|
|
93
|
+
New locations are typically created each time the URL changes. You can read more about locations in [the `history` docs](https://github.com/ReactTraining/history/blob/v3/docs/Location.md).
|
|
93
94
|
|
|
94
95
|
### LocationDescriptor
|
|
95
96
|
|
|
96
97
|
type LocationDescriptorObject = {
|
|
97
98
|
pathname: Pathname;
|
|
98
|
-
search
|
|
99
|
-
query
|
|
100
|
-
state
|
|
99
|
+
search?: Search;
|
|
100
|
+
query?: Query;
|
|
101
|
+
state?: LocationState;
|
|
101
102
|
};
|
|
102
103
|
|
|
103
104
|
type LocationDescriptor = LocationDescriptorObject | Path;
|
|
104
105
|
|
|
105
106
|
A *location descriptor* is the pushable analogue of a location. Locations tell you where you are; you create location descriptors to say where to go.
|
|
106
107
|
|
|
107
|
-
You can read more about location descriptors in [the `history` docs](https://github.com/
|
|
108
|
+
You can read more about location descriptors in [the `history` docs](https://github.com/ReactTraining/history/blob/v3/docs/Location.md).
|
|
108
109
|
|
|
109
110
|
## LocationKey
|
|
110
111
|
|
|
@@ -170,7 +171,7 @@ A *query string* is the portion of the URL that follows the [pathname](#pathname
|
|
|
170
171
|
## RedirectFunction
|
|
171
172
|
|
|
172
173
|
```js
|
|
173
|
-
type RedirectFunction = (
|
|
174
|
+
type RedirectFunction = (location: LocationDescriptor) => void;
|
|
174
175
|
```
|
|
175
176
|
|
|
176
177
|
A *redirect function* is used in [`onEnter` hooks](#enterhook) to trigger a transition to a new URL.
|
|
@@ -179,10 +180,10 @@ A *redirect function* is used in [`onEnter` hooks](#enterhook) to trigger a tran
|
|
|
179
180
|
|
|
180
181
|
```js
|
|
181
182
|
type Route = {
|
|
182
|
-
component
|
|
183
|
-
path
|
|
184
|
-
onEnter
|
|
185
|
-
onLeave
|
|
183
|
+
component?: RouteComponent;
|
|
184
|
+
path?: RoutePattern;
|
|
185
|
+
onEnter?: EnterHook;
|
|
186
|
+
onLeave?: LeaveHook;
|
|
186
187
|
};
|
|
187
188
|
```
|
|
188
189
|
|
package/docs/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# React Router 3 Documentation
|
|
2
|
+
|
|
1
3
|
## Table of Contents
|
|
2
4
|
|
|
3
5
|
* [Tutorial](https://github.com/reactjs/react-router-tutorial)
|
|
@@ -19,5 +21,5 @@
|
|
|
19
21
|
* [Upgrading to v1.0.0](../upgrade-guides/v1.0.0.md)
|
|
20
22
|
* [Upgrading to v2.0.0](../upgrade-guides/v2.0.0.md)
|
|
21
23
|
* [Troubleshooting](Troubleshooting.md)
|
|
22
|
-
* [API](API.md)
|
|
24
|
+
* [React Router 3 API](API.md)
|
|
23
25
|
* [Glossary](Glossary.md)
|
|
@@ -46,4 +46,4 @@ const CourseRoute = {
|
|
|
46
46
|
|
|
47
47
|
Now go look at what hacks you have in place to do this. Just kidding, I don't want to make you sad right now.
|
|
48
48
|
|
|
49
|
-
Run the [huge apps](https://github.com/ReactTraining/react-router/tree/
|
|
49
|
+
Run the [huge apps](https://github.com/ReactTraining/react-router/tree/v3/examples/huge-apps) example with your web inspector open and watch code get loaded in as you navigate around the demo.
|
|
@@ -168,7 +168,7 @@ Now when someone clicks on that link to `/inbox/messages/5` they'll automaticall
|
|
|
168
168
|
|
|
169
169
|
### Enter and Leave Hooks
|
|
170
170
|
|
|
171
|
-
[Route](/docs/Glossary.md#route)s may also define [`onEnter`](/docs/Glossary.md#enterhook) and [`onLeave`](/docs/Glossary.md#leavehook) hooks that are invoked once a transition has been [confirmed](/docs/guides/ConfirmingNavigation.md). These hooks are useful for various things like [requiring auth](https://github.com/ReactTraining/react-router/tree/
|
|
171
|
+
[Route](/docs/Glossary.md#route)s may also define [`onEnter`](/docs/Glossary.md#enterhook) and [`onLeave`](/docs/Glossary.md#leavehook) hooks that are invoked once a transition has been [confirmed](/docs/guides/ConfirmingNavigation.md). These hooks are useful for various things like [requiring auth](https://github.com/ReactTraining/react-router/tree/v3/examples/auth-flow) when a route is entered and saving stuff to persistent storage before a route unmounts.
|
|
172
172
|
|
|
173
173
|
During a transition, [`onLeave` hooks](/docs/Glossary.md#leavehook) run first on all routes we are leaving, starting with the leaf route on up to the first common ancestor route. Next, [`onEnter` hooks](/docs/Glossary.md#enterhook) run starting with the first parent route we're entering down to the leaf route.
|
|
174
174
|
|
package/docs/guides/Testing.md
CHANGED
|
@@ -73,7 +73,8 @@ A component:
|
|
|
73
73
|
```js
|
|
74
74
|
//../components/BasicPage.js
|
|
75
75
|
|
|
76
|
-
import React, { Component
|
|
76
|
+
import React, { Component } from 'react'
|
|
77
|
+
import PropTypes from 'prop-types'
|
|
77
78
|
import { Button } from 'react-bootstrap'
|
|
78
79
|
import { Link } from 'react-router'
|
|
79
80
|
|
package/es/IndexLink.js
CHANGED
|
@@ -8,6 +8,8 @@ import Link from './Link';
|
|
|
8
8
|
* An <IndexLink> is used to link to an <IndexRoute>.
|
|
9
9
|
*/
|
|
10
10
|
var IndexLink = createReactClass({
|
|
11
|
+
displayName: 'IndexLink',
|
|
12
|
+
|
|
11
13
|
render: function render() {
|
|
12
14
|
return React.createElement(Link, _extends({}, this.props, { onlyActiveOnIndex: true }));
|
|
13
15
|
}
|
package/es/IndexRedirect.js
CHANGED
|
@@ -10,6 +10,7 @@ import { falsy } from './InternalPropTypes';
|
|
|
10
10
|
*/
|
|
11
11
|
/* eslint-disable react/require-render-return */
|
|
12
12
|
var IndexRedirect = createReactClass({
|
|
13
|
+
displayName: 'IndexRedirect',
|
|
13
14
|
|
|
14
15
|
statics: {
|
|
15
16
|
createRouteFromReactElement: function createRouteFromReactElement(element, parentRoute) {
|
package/es/IndexRoute.js
CHANGED
|
@@ -11,6 +11,7 @@ import { component, components, falsy } from './InternalPropTypes';
|
|
|
11
11
|
*/
|
|
12
12
|
/* eslint-disable react/require-render-return */
|
|
13
13
|
var IndexRoute = createReactClass({
|
|
14
|
+
displayName: 'IndexRoute',
|
|
14
15
|
|
|
15
16
|
statics: {
|
|
16
17
|
createRouteFromReactElement: function createRouteFromReactElement(element, parentRoute) {
|
package/es/Link.js
CHANGED
package/es/Redirect.js
CHANGED
|
@@ -14,6 +14,7 @@ import { falsy } from './InternalPropTypes';
|
|
|
14
14
|
*/
|
|
15
15
|
/* eslint-disable react/require-render-return */
|
|
16
16
|
var Redirect = createReactClass({
|
|
17
|
+
displayName: 'Redirect',
|
|
17
18
|
|
|
18
19
|
statics: {
|
|
19
20
|
createRouteFromReactElement: function createRouteFromReactElement(element) {
|
package/es/Route.js
CHANGED
package/es/Router.js
CHANGED
|
@@ -25,14 +25,14 @@ var propTypes = {
|
|
|
25
25
|
|
|
26
26
|
// PRIVATE: For client-side rehydration of server match.
|
|
27
27
|
matchContext: object
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A <Router> is a high-level API for automatically setting up
|
|
31
|
+
* a router that renders a <RouterContext> with all the props
|
|
32
|
+
* it needs each time the URL changes.
|
|
33
|
+
*/
|
|
34
|
+
};var Router = createReactClass({
|
|
35
|
+
displayName: 'Router',
|
|
36
36
|
|
|
37
37
|
propTypes: propTypes,
|
|
38
38
|
|
package/es/RouterContext.js
CHANGED
package/es/TransitionUtils.js
CHANGED
|
@@ -28,121 +28,129 @@ var PendingHooks = function PendingHooks() {
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
var
|
|
31
|
+
export default function getTransitionUtils() {
|
|
32
|
+
var enterHooks = new PendingHooks();
|
|
33
|
+
var changeHooks = new PendingHooks();
|
|
33
34
|
|
|
34
|
-
function createTransitionHook(hook, route, asyncArity, pendingHooks) {
|
|
35
|
-
|
|
35
|
+
function createTransitionHook(hook, route, asyncArity, pendingHooks) {
|
|
36
|
+
var isSync = hook.length < asyncArity;
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
var transitionHook = function transitionHook() {
|
|
39
|
+
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
40
|
+
args[_key] = arguments[_key];
|
|
41
|
+
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
hook.apply(route, args);
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
if (isSync) {
|
|
46
|
+
var callback = args[args.length - 1];
|
|
47
|
+
// Assume hook executes synchronously and
|
|
48
|
+
// automatically call the callback.
|
|
49
|
+
callback();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
pendingHooks.add(transitionHook);
|
|
54
|
+
|
|
55
|
+
return transitionHook;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getEnterHooks(routes) {
|
|
59
|
+
return routes.reduce(function (hooks, route) {
|
|
60
|
+
if (route.onEnter) hooks.push(createTransitionHook(route.onEnter, route, 3, enterHooks));
|
|
61
|
+
return hooks;
|
|
62
|
+
}, []);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function getChangeHooks(routes) {
|
|
66
|
+
return routes.reduce(function (hooks, route) {
|
|
67
|
+
if (route.onChange) hooks.push(createTransitionHook(route.onChange, route, 4, changeHooks));
|
|
68
|
+
return hooks;
|
|
69
|
+
}, []);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function runTransitionHooks(length, iter, callback) {
|
|
73
|
+
if (!length) {
|
|
48
74
|
callback();
|
|
75
|
+
return;
|
|
49
76
|
}
|
|
50
|
-
};
|
|
51
77
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (route.onChange) hooks.push(createTransitionHook(route.onChange, route, 4, changeHooks));
|
|
67
|
-
return hooks;
|
|
68
|
-
}, []);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function runTransitionHooks(length, iter, callback) {
|
|
72
|
-
if (!length) {
|
|
73
|
-
callback();
|
|
74
|
-
return;
|
|
78
|
+
var redirectInfo = void 0;
|
|
79
|
+
function replace(location) {
|
|
80
|
+
redirectInfo = location;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
loopAsync(length, function (index, next, done) {
|
|
84
|
+
iter(index, replace, function (error) {
|
|
85
|
+
if (error || redirectInfo) {
|
|
86
|
+
done(error, redirectInfo); // No need to continue.
|
|
87
|
+
} else {
|
|
88
|
+
next();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}, callback);
|
|
75
92
|
}
|
|
76
93
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Runs all onEnter hooks in the given array of routes in order
|
|
96
|
+
* with onEnter(nextState, replace, callback) and calls
|
|
97
|
+
* callback(error, redirectInfo) when finished. The first hook
|
|
98
|
+
* to use replace short-circuits the loop.
|
|
99
|
+
*
|
|
100
|
+
* If a hook needs to run asynchronously, it may use the callback
|
|
101
|
+
* function. However, doing so will cause the transition to pause,
|
|
102
|
+
* which could lead to a non-responsive UI if the hook is slow.
|
|
103
|
+
*/
|
|
104
|
+
function runEnterHooks(routes, nextState, callback) {
|
|
105
|
+
enterHooks.clear();
|
|
106
|
+
var hooks = getEnterHooks(routes);
|
|
107
|
+
return runTransitionHooks(hooks.length, function (index, replace, next) {
|
|
108
|
+
var wrappedNext = function wrappedNext() {
|
|
109
|
+
if (enterHooks.has(hooks[index])) {
|
|
110
|
+
next.apply(undefined, arguments);
|
|
111
|
+
enterHooks.remove(hooks[index]);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
hooks[index](nextState, replace, wrappedNext);
|
|
115
|
+
}, callback);
|
|
80
116
|
}
|
|
81
117
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
hooks[index](nextState, replace, wrappedNext);
|
|
114
|
-
}, callback);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Runs all onChange hooks in the given array of routes in order
|
|
119
|
-
* with onChange(prevState, nextState, replace, callback) and calls
|
|
120
|
-
* callback(error, redirectInfo) when finished. The first hook
|
|
121
|
-
* to use replace short-circuits the loop.
|
|
122
|
-
*
|
|
123
|
-
* If a hook needs to run asynchronously, it may use the callback
|
|
124
|
-
* function. However, doing so will cause the transition to pause,
|
|
125
|
-
* which could lead to a non-responsive UI if the hook is slow.
|
|
126
|
-
*/
|
|
127
|
-
export function runChangeHooks(routes, state, nextState, callback) {
|
|
128
|
-
changeHooks.clear();
|
|
129
|
-
var hooks = getChangeHooks(routes);
|
|
130
|
-
return runTransitionHooks(hooks.length, function (index, replace, next) {
|
|
131
|
-
var wrappedNext = function wrappedNext() {
|
|
132
|
-
if (changeHooks.has(hooks[index])) {
|
|
133
|
-
next.apply(undefined, arguments);
|
|
134
|
-
changeHooks.remove(hooks[index]);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
hooks[index](state, nextState, replace, wrappedNext);
|
|
138
|
-
}, callback);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Runs all onLeave hooks in the given array of routes in order.
|
|
143
|
-
*/
|
|
144
|
-
export function runLeaveHooks(routes, prevState) {
|
|
145
|
-
for (var i = 0, len = routes.length; i < len; ++i) {
|
|
146
|
-
if (routes[i].onLeave) routes[i].onLeave.call(routes[i], prevState);
|
|
118
|
+
/**
|
|
119
|
+
* Runs all onChange hooks in the given array of routes in order
|
|
120
|
+
* with onChange(prevState, nextState, replace, callback) and calls
|
|
121
|
+
* callback(error, redirectInfo) when finished. The first hook
|
|
122
|
+
* to use replace short-circuits the loop.
|
|
123
|
+
*
|
|
124
|
+
* If a hook needs to run asynchronously, it may use the callback
|
|
125
|
+
* function. However, doing so will cause the transition to pause,
|
|
126
|
+
* which could lead to a non-responsive UI if the hook is slow.
|
|
127
|
+
*/
|
|
128
|
+
function runChangeHooks(routes, state, nextState, callback) {
|
|
129
|
+
changeHooks.clear();
|
|
130
|
+
var hooks = getChangeHooks(routes);
|
|
131
|
+
return runTransitionHooks(hooks.length, function (index, replace, next) {
|
|
132
|
+
var wrappedNext = function wrappedNext() {
|
|
133
|
+
if (changeHooks.has(hooks[index])) {
|
|
134
|
+
next.apply(undefined, arguments);
|
|
135
|
+
changeHooks.remove(hooks[index]);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
hooks[index](state, nextState, replace, wrappedNext);
|
|
139
|
+
}, callback);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Runs all onLeave hooks in the given array of routes in order.
|
|
144
|
+
*/
|
|
145
|
+
function runLeaveHooks(routes, prevState) {
|
|
146
|
+
for (var i = 0, len = routes.length; i < len; ++i) {
|
|
147
|
+
if (routes[i].onLeave) routes[i].onLeave.call(routes[i], prevState);
|
|
148
|
+
}
|
|
147
149
|
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
runEnterHooks: runEnterHooks,
|
|
153
|
+
runChangeHooks: runChangeHooks,
|
|
154
|
+
runLeaveHooks: runLeaveHooks
|
|
155
|
+
};
|
|
148
156
|
}
|
|
@@ -2,7 +2,7 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
|
|
|
2
2
|
|
|
3
3
|
import warning from './routerWarning';
|
|
4
4
|
import computeChangedRoutes from './computeChangedRoutes';
|
|
5
|
-
import
|
|
5
|
+
import getTransitionUtils from './TransitionUtils';
|
|
6
6
|
import _isActive from './isActive';
|
|
7
7
|
import getComponents from './getComponents';
|
|
8
8
|
import matchRoutes from './matchRoutes';
|
|
@@ -16,8 +16,15 @@ function hasAnyProperties(object) {
|
|
|
16
16
|
export default function createTransitionManager(history, routes) {
|
|
17
17
|
var state = {};
|
|
18
18
|
|
|
19
|
+
var _getTransitionUtils = getTransitionUtils(),
|
|
20
|
+
runEnterHooks = _getTransitionUtils.runEnterHooks,
|
|
21
|
+
runChangeHooks = _getTransitionUtils.runChangeHooks,
|
|
22
|
+
runLeaveHooks = _getTransitionUtils.runLeaveHooks;
|
|
23
|
+
|
|
19
24
|
// Signature should be (location, indexOnly), but needs to support (path,
|
|
20
25
|
// query, indexOnly)
|
|
26
|
+
|
|
27
|
+
|
|
21
28
|
function isActive(location, indexOnly) {
|
|
22
29
|
location = history.createLocation(location);
|
|
23
30
|
|
package/es/withRouter.js
CHANGED
|
@@ -15,6 +15,8 @@ export default function withRouter(WrappedComponent, options) {
|
|
|
15
15
|
var withRef = options && options.withRef;
|
|
16
16
|
|
|
17
17
|
var WithRouter = createReactClass({
|
|
18
|
+
displayName: 'WithRouter',
|
|
19
|
+
|
|
18
20
|
mixins: [ContextSubscriber('router')],
|
|
19
21
|
|
|
20
22
|
contextTypes: { router: routerShape },
|
package/lib/IndexLink.js
CHANGED
|
@@ -22,6 +22,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
22
22
|
* An <IndexLink> is used to link to an <IndexRoute>.
|
|
23
23
|
*/
|
|
24
24
|
var IndexLink = (0, _createReactClass2.default)({
|
|
25
|
+
displayName: 'IndexLink',
|
|
26
|
+
|
|
25
27
|
render: function render() {
|
|
26
28
|
return _react2.default.createElement(_Link2.default, _extends({}, this.props, { onlyActiveOnIndex: true }));
|
|
27
29
|
}
|
package/lib/IndexRedirect.js
CHANGED
|
@@ -29,6 +29,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
29
29
|
*/
|
|
30
30
|
/* eslint-disable react/require-render-return */
|
|
31
31
|
var IndexRedirect = (0, _createReactClass2.default)({
|
|
32
|
+
displayName: 'IndexRedirect',
|
|
32
33
|
|
|
33
34
|
statics: {
|
|
34
35
|
createRouteFromReactElement: function createRouteFromReactElement(element, parentRoute) {
|
package/lib/IndexRoute.js
CHANGED
|
@@ -28,6 +28,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
28
28
|
*/
|
|
29
29
|
/* eslint-disable react/require-render-return */
|
|
30
30
|
var IndexRoute = (0, _createReactClass2.default)({
|
|
31
|
+
displayName: 'IndexRoute',
|
|
31
32
|
|
|
32
33
|
statics: {
|
|
33
34
|
createRouteFromReactElement: function createRouteFromReactElement(element, parentRoute) {
|
package/lib/Link.js
CHANGED
package/lib/Redirect.js
CHANGED
|
@@ -29,6 +29,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
29
29
|
*/
|
|
30
30
|
/* eslint-disable react/require-render-return */
|
|
31
31
|
var Redirect = (0, _createReactClass2.default)({
|
|
32
|
+
displayName: 'Redirect',
|
|
32
33
|
|
|
33
34
|
statics: {
|
|
34
35
|
createRouteFromReactElement: function createRouteFromReactElement(element) {
|
package/lib/Route.js
CHANGED
|
@@ -30,6 +30,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
30
30
|
*/
|
|
31
31
|
/* eslint-disable react/require-render-return */
|
|
32
32
|
var Route = (0, _createReactClass2.default)({
|
|
33
|
+
displayName: 'Route',
|
|
33
34
|
|
|
34
35
|
statics: {
|
|
35
36
|
createRouteFromReactElement: _RouteUtils.createRouteFromReactElement
|
package/lib/Router.js
CHANGED
|
@@ -51,14 +51,14 @@ var propTypes = {
|
|
|
51
51
|
|
|
52
52
|
// PRIVATE: For client-side rehydration of server match.
|
|
53
53
|
matchContext: _propTypes.object
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A <Router> is a high-level API for automatically setting up
|
|
57
|
+
* a router that renders a <RouterContext> with all the props
|
|
58
|
+
* it needs each time the URL changes.
|
|
59
|
+
*/
|
|
60
|
+
};var Router = (0, _createReactClass2.default)({
|
|
61
|
+
displayName: 'Router',
|
|
62
62
|
|
|
63
63
|
propTypes: propTypes,
|
|
64
64
|
|
package/lib/RouterContext.js
CHANGED
|
@@ -35,6 +35,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
35
35
|
* and sets the history object and the current location in context.
|
|
36
36
|
*/
|
|
37
37
|
var RouterContext = (0, _createReactClass2.default)({
|
|
38
|
+
displayName: 'RouterContext',
|
|
38
39
|
|
|
39
40
|
mixins: [(0, _ContextUtils.ContextProvider)('router')],
|
|
40
41
|
|