我正在使用react-router-dom我正在从屏幕A导航到屏幕B,并指定状态clearData
。如下所示:
this.props.history.push({pathname: '/B', state: {clearData: true}})
现在,当我从屏幕B导航到屏幕C并返回到屏幕B时,我想清除屏幕B中的状态clearData
。如何实现?
提前感谢:)
实现此用途
componentWillRecieveProps(props){
if(props.location.state !==this.props.location.state &&
props.location.state.clearData){
this.setState(initial_state_obj)
}
您也可以在componentDidMount事件上获取它!