Skip to content

Commit 2a82ef1

Browse files
authored
Update API.md
1 parent 8ecae83 commit 2a82ef1

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

docs/API.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,25 +349,22 @@ If `callback` is listed as a 3rd argument, this hook will run asynchronously, an
349349
`cb(err)`
350350

351351
```js
352-
const userIsInAnTeam = (nextState, replace, callback) => {
352+
const userIsInATeam = (nextState, replace, callback) => {
353353
fetch(...)
354354
.then(response = response.json())
355355
.then(userTeams => {
356356
if (userTeams.length === 0) {
357-
replace({
358-
pathname: '/users/' + nextState.params.userId + '/teams/new',
359-
state: { nextPathname: nextState.location.pathname }
360-
})
357+
replace(`/users/${nextState.params.userId}/teams/new`)
361358
}
362359
callback();
363360
})
364361
.catch(error => {
365362
// do some error handling here
366-
callback();
363+
callback(error);
367364
})
368365
}
369366

370-
<Route path="/users/:userId/teams" onEnter={userIsInAnTeam} />
367+
<Route path="/users/:userId/teams" onEnter={userIsInATeam} />
371368
```
372369

373370
##### `onChange(prevState, nextState, replace, callback?)`

0 commit comments

Comments
 (0)