Skip to content

Instantly share code, notes, and snippets.

@eyalcohen4
Created April 27, 2018 14:26
Show Gist options
  • Save eyalcohen4/450182ebc8ff48154c2c73f5b39fc7c4 to your computer and use it in GitHub Desktop.
Save eyalcohen4/450182ebc8ff48154c2c73f5b39fc7c4 to your computer and use it in GitHub Desktop.
Preventing Transitions in react router 4
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