Guest User

Untitled

a guest
Feb 16th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. class ProjectContainer extends Component {
  2. constructor(props) {
  3. super(props);
  4. this.onBeforeUnload = this.onBeforeUnload.bind(this);
  5. }
  6.  
  7. componentDidMount() {
  8. window.addEventListener('beforeunload', this.onBeforeUnload);
  9. }
  10.  
  11. componentWillUnmount() {
  12. window.removeEventListener('beforeunload', this.onBeforeUnload);
  13. }
  14.  
  15. onBeforeUnload(event) {
  16. const { history } = this.props;
  17. if (history.location.pathname !== '/saving-package') {
  18. event.returnValue = 'Changes will not be saved. This action cannot be undone';
  19. }
  20. }
  21.  
  22. render() {
  23. const { routes } = this.props;
  24. return (
  25. // ...routes
  26. );
  27. }
  28. }
Add Comment
Please, Sign In to add comment