I have an application that has a cart in redux store. When user completes the purchase. I Reset (redux store) the cart when moves out of the Final page. But when user clicks the browser back button. The redux store is back with the previous data. How do I clear the redux store completely? There is no Login/Registration Required for Purchase. I am using Reactjs with Redux (with redux-thunk).
When user hits backbutton - (don't take to previous page i.e. payment page again)
componentDidMount () {
window.onpopstate = this.onBackButtonEvent
}
onBackButtonEvent = (e) => {
e.preventDefault()
console.log('in backbutton')
this.props.history.push('/insta-repair')
this.props.resetCart()
window.onpopstate = () => {}
}
cart action
export const resetCart = () => ({
type: cartActionTypes.RESET_CART,
data: []
})
cart reducer
case CartTypes.RESET_CART:
return {
...initialState,
item: action.data
}
The problem
When user hits browser back button. Then the Previous redux store data is accessible. Is there a way to completely Reset the Store?