Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const RouteComponent = React.createClass({
const RouteComponent = React.createClass({
componentDidMount() {
const { router, route } = this.props
router.addRouteLeaveHook(route, this.routerWillLeave)
router.setRouteLeaveHook(route, this.routerWillLeave)
}
})

Expand Down Expand Up @@ -171,7 +171,7 @@ const DeepComponent = React.createClass({

componentDidMount() {
const { router, route } = this.context
router.addRouteLeaveHook(route, this.routerWillLeave)
router.setRouteLeaveHook(route, this.routerWillLeave)
}
})

Expand All @@ -187,7 +187,7 @@ const Lifecycle = {
componentDidMount() {
const router = this.context.router
const route = this.props.route || this.context.route
router.addRouteLeaveHook(route, this.routerWillLeave)
router.setRouteLeaveHook(route, this.routerWillLeave)
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion examples/transitions/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Dashboard = React.createClass({
const Form = React.createClass({

componentWillMount() {
this.props.router.addRouteLeaveHook(
this.props.router.setRouteLeaveHook(
this.props.route,
this.routerWillLeave
)
Expand Down
2 changes: 1 addition & 1 deletion modules/Lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Lifecycle = {
},

componentDidMount() {
warning(false, 'the `Lifecycle` mixin is deprecated, please use `this.props.router.addRouteLeaveHook(this.props.route, hook)` from a route component, see https://github.com/rackt/react-router/blob/v1.1.0/CHANGES.md#v110 for more details.')
warning(false, 'the `Lifecycle` mixin is deprecated, please use `this.props.router.setRouteLeaveHook(this.props.route, hook)` from a route component, see https://github.com/rackt/react-router/blob/v1.1.0/CHANGES.md#v110 for more details.')
invariant(
this.routerWillLeave,
'The Lifecycle mixin requires you to define a routerWillLeave method'
Expand Down
2 changes: 1 addition & 1 deletion modules/RouterContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const RouterContext = React.createClass({

router = {
...history,
addRouteLeaveHook: history.listenBeforeLeavingRoute
setRouteLeaveHook: history.listenBeforeLeavingRoute
}
delete router.listenBeforeLeavingRoute
}
Expand Down
2 changes: 1 addition & 1 deletion modules/RouterUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import deprecateObjectProperties from './deprecateObjectProperties'
export function createRouterObject(history, transitionManager) {
return {
...history,
addRouteLeaveHook: transitionManager.listenBeforeLeavingRoute,
setRouteLeaveHook: transitionManager.listenBeforeLeavingRoute,
isActive: transitionManager.isActive
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/__tests__/RouterContext-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ describe('RouterContext', () => {
})
})

it('proxies calls to `addRouteLeaveHook` to `props.transitionManager`', (done) => {
it('proxies calls to `setRouteLeaveHook` to `props.transitionManager`', (done) => {
const args = [ 1, 2, 3 ]
renderTest(() => {
const remove = context.router.addRouteLeaveHook(...args)
const remove = context.router.setRouteLeaveHook(...args)
expect(transitionManager.listenBeforeLeavingRoute).toHaveBeenCalledWith(...args)
expect(remove).toBe(listenBeforeLeavingRouteSentinel)
done()
Expand Down
2 changes: 1 addition & 1 deletion modules/__tests__/transitionHooks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('When a router enters a branch', function () {

class NewsFeed extends Component {
componentWillMount() {
removeLeaveHook = this.context.router.addRouteLeaveHook(
removeLeaveHook = this.context.router.setRouteLeaveHook(
this.props.route,
() => leaveHookSpy() // Break reference equality.
)
Expand Down
11 changes: 9 additions & 2 deletions modules/createTransitionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,15 @@ export default function createTransitionManager(history, routes) {
if (history.listenBeforeUnload)
unlistenBeforeUnload = history.listenBeforeUnload(beforeUnloadHook)
}
} else if (hooks.indexOf(hook) === -1) {
hooks.push(hook)
} else {
warning(
false,
'adding multiple leave hooks for the same route is deprecated; manage multiple confirmations in your own code instead'
)

if (hooks.indexOf(hook) === -1) {
hooks.push(hook)
}
}

return function () {
Expand Down