mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-29 13:06:03 +10:00
Listen to history changes only when possible
This commit is contained in:
parent
3f4bc073d4
commit
763db75553
1 changed files with 6 additions and 2 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue