score:0

componentDidMount() {
    if (window.addEventListener) {            
        window.addEventListener('beforeunload', this.onUnloadPage);
    } else {            
        window.attachEvent('onbeforeunload', this.onUnloadPage);
    }
}

componentWillUnmount() {
    if (window.addEventListener) {
        window.removeEventListener('beforeunload', this.onUnloadPage);
    } else {
        window.detachEvent('onbeforeunload', this.onUnloadPage);
    }
}

onUnloadPage = (event) => {
    window.setTimeout(function () {
        window.location = '/collections/';
    }, 0);
    window.onbeforeunload = null;
};

Related Query

More Query from same tag