Skip to content

Commit 08d0057

Browse files
committed
Merge branch 'master' into next
2 parents f676dcb + 5538899 commit 08d0057

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ React Router keeps your UI in sync with the URL. It has a simple API with powerf
2222

2323
**Older Versions:**
2424

25-
- 0.13.x - [docs](https://github.com/reactjs/react-router/tree/0.13.x/doc) / [guides](https://github.com/reactjs/react-router/tree/0.13.x/docs/guides) / [code](https://github.com/reactjs/react-router/tree/0.13.x) / [upgrade guide](https://github.com/reactjs/react-router/blob/master/upgrade-guides/v1.0.0.md)
25+
- 0.13.x - [docs](https://github.com/reactjs/react-router/tree/v0.13.6/doc) / [guides](https://github.com/reactjs/react-router/tree/v0.13.6/docs/guides) / [code](https://github.com/reactjs/react-router/tree/v0.13.6) / [upgrade guide](https://github.com/reactjs/react-router/blob/master/upgrade-guides/v1.0.0.md)
2626
- 1.0.x - [docs](https://github.com/reactjs/react-router/tree/1.0.x/docs) / [code](https://github.com/reactjs/react-router/tree/1.0.x) / [upgrade guide](https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md)
2727

2828
For questions and support, please visit [our channel on Reactiflux](https://discord.gg/0ZcbPKXt5bYaNQ46) or [Stack Overflow](http://stackoverflow.com/questions/tagged/react-router).

docs/API.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,28 @@ Called when a route is about to be entered. It provides the next router state an
328328

329329
If `callback` is listed as a 3rd argument, this hook will run asynchronously, and the transition will block until `callback` is called.
330330

331+
###### `callback` signature
332+
`cb(err)`
333+
334+
```js
335+
const userIsInATeam = (nextState, replace, callback) => {
336+
fetch(...)
337+
.then(response = response.json())
338+
.then(userTeams => {
339+
if (userTeams.length === 0) {
340+
replace(`/users/${nextState.params.userId}/teams/new`)
341+
}
342+
callback();
343+
})
344+
.catch(error => {
345+
// do some error handling here
346+
callback(error);
347+
})
348+
}
349+
350+
<Route path="/users/:userId/teams" onEnter={userIsInATeam} />
351+
```
352+
331353
##### `onChange(prevState, nextState, replace, callback?)`
332354
Called on routes when the location changes, but the route itself neither enters or leaves. For example, this will be called when a route's children change, or when the location query changes. It provides the previous router state, the next router state, and a function to redirect to another path. `this` will be the route instance that triggered the hook.
333355

0 commit comments

Comments
 (0)