Created
April 27, 2018 14:26
-
-
Save eyalcohen4/450182ebc8ff48154c2c73f5b39fc7c4 to your computer and use it in GitHub Desktop.
Preventing Transitions in react router 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
class App extends Component { | |
this.unblock = this.props.history.block(nextLocation => this.getShouldBlockTransition(nextLocation)); | |
getShouldBlockTransition = nextLocation => { | |
// shouldBlock is a boolean which represent if history should block/not to block. | |
// If set to true, the user wont be able to exit, and on false he will. | |
return shouldBlock; | |
} | |
render() { | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment