Skip to content

Commit 7a8fe1b

Browse files
committed
Fix browser back button with multiple dcc.Location
Multiple dcc.Location were replacing the others event handlers for 'popstate'. If any dcc.Location was unmounted, there was no event handler left fix #1312
1 parent db23cdc commit 7a8fe1b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

components/dash-core-components/src/components/Location.react.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ export default class Location extends Component {
112112
}
113113

114114
componentDidMount() {
115-
window.onpopstate = this.onLocationChange;
115+
window.addEventListener(
116+
'popstate',
117+
this.onLocationChange
118+
)
116119

117120
window.addEventListener(
118121
'_dashprivate_pushstate',
@@ -122,7 +125,10 @@ export default class Location extends Component {
122125
}
123126

124127
componentWillUnmount() {
125-
window.onpopstate = () => {};
128+
window.removeEventListener(
129+
'popstate',
130+
this.onLocationChange
131+
)
126132
window.removeEventListener(
127133
'_dashprivate_pushstate',
128134
this.onLocationChange

0 commit comments

Comments
 (0)