Skip to content

Commit

Permalink
Fix browser back button with multiple dcc.Location
Browse files Browse the repository at this point in the history
Multiple dcc.Location were replacing the others event handlers for
'popstate'. If any dcc.Location was unmounted, there was no event
handler left

fix plotly#1312
  • Loading branch information
jowlo committed Jun 1, 2023
1 parent db23cdc commit 7a8fe1b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions components/dash-core-components/src/components/Location.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ export default class Location extends Component {
}

componentDidMount() {
window.onpopstate = this.onLocationChange;
window.addEventListener(
'popstate',
this.onLocationChange
)

window.addEventListener(
'_dashprivate_pushstate',
Expand All @@ -122,7 +125,10 @@ export default class Location extends Component {
}

componentWillUnmount() {
window.onpopstate = () => {};
window.removeEventListener(
'popstate',
this.onLocationChange
)
window.removeEventListener(
'_dashprivate_pushstate',
this.onLocationChange
Expand Down

0 comments on commit 7a8fe1b

Please sign in to comment.