【发布时间】:2020-09-21 19:48:14
【问题描述】:
我有一个在 redux 商店中有购物车的应用程序。当用户完成购买时。移出最终页面时,我重置(redux 存储)购物车。 但是当用户点击浏览器后退按钮时。 redux store 恢复了之前的数据。 如何彻底清除 redux store?购买无需登录/注册。我正在将 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 数据。有没有办法完全重置商店?
【问题讨论】:
-
请随时使用Minimal, Complete, and Reproducible 代码示例更新您的问题,以便此处的其他人可以看到您正在使用的内容。另一种方法可能是通过购买流程控制导航(通过重定向),这样任何后退导航都会将用户带到流程的开头,而不是在中间的某个点以某种不确定的状态。
-
你是如何重置状态的?
标签: reactjs redux redux-store