Skip to content

Commit

Permalink
Add a popstate handler
Browse files Browse the repository at this point in the history
Add history state for back/forward navigation.
  • Loading branch information
eatyourgreens committed Mar 30, 2022
1 parent 3f5d08d commit c6fe331
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/lib-classifier/dev/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ class App extends React.Component {
}

componentDidMount () {
addEventListener('popstate', this.onPopState.bind(this))
this.initAuthorization()
.then(() => {
this.fetchProject()
})
}

onPopState({ state }) {
const url = new URL(window.location)
const { searchParams } = url
const workflowID = searchParams.get('workflow')
this.setState({ workflowID })
}

onError (error, info) {
console.error(error)
}
Expand Down Expand Up @@ -125,7 +133,7 @@ class App extends React.Component {
} else {
newParams.set('workflow', workflowID)
}
history.pushState(null, '', `/?${newParams.toString()}`)
history.pushState({ workflowID }, '', `/?${newParams.toString()}`)
}

toggleTheme () {
Expand Down

0 comments on commit c6fe331

Please sign in to comment.