我有一个在 redux 商店中有购物车的应用程序。当用户完成购买时。移出最终页面时,我重置(redux 存储)购物车。但是当用户单击浏览器后退按钮时。redux 存储返回之前的数据。如何彻底清除 redux 商店?购买无需登录/注册。我正在将 Reactjs 与 Redux(使用 redux-thunk)一起使用。
当用户点击后退按钮时 - (不要转到上一页,即再次付款页面)
componentDidMount () {
window.onpopstate = this.onBackButtonEvent
}
onBackButtonEvent = (e) => {
e.preventDefault()
console.log('in backbutton')
this.props.history.push('/insta-repair')
this.props.resetCart()
window.onpopstate = () => {}
}
购物车动作
export const resetCart = () => ({
type: cartActionTypes.RESET_CART,
data: []
})
推车减速机
case CartTypes.RESET_CART:
return {
...initialState,
item: action.data
}
问题
当用户点击浏览器后退按钮时。然后可以访问Previous redux store 数据。有没有办法完全重置商店?