Listen to history changes only when possible

This commit is contained in:
Kimmo Puputti 2017-02-14 14:19:14 +02:00
parent 3f4bc073d4
commit 763db75553

View file

@ -10,11 +10,15 @@ const scrollToTop = () => {
class PageLayout extends Component {
componentDidMount() {
this.historyUnlisten = this.context.history.listen(() => scrollToTop());
if (this.context && this.context.history && this.context.history.listen) {
this.historyUnlisten = this.context.history.listen(() => scrollToTop());
}
}
componentWillUnmount() {
this.historyUnlisten();
if (this.historyUnlisten) {
this.historyUnlisten();
}
}
render() {