'react-router-dom' has refresh function here, but I don't know how to call this method, also their well formatted document doesn't bother to explain this.
window.location.reload() doesn't work for me, because it wipes out the app store as well. I changed some data, and then need to reload the route with updated data.
I also read this:
https://github.com/ReactTraining/react-router/issues/1982
https://github.com/ReactTraining/react-router/issues/2243
this thread is exactly discussing my question:
https://github.com/ReactTraining/react-router/issues/4056
and still clueless how to do it. This basic function should not require too much effort, but after spending huge amount of effort, I can't reload current route.
here is my code:
@inject('store') @observer
export default class PasswordInput extends Component {
constructor (props) {
super(props)
this.setPwd = this.setPwd.bind(this)
this.submit = this.submit.bind(this)
}
componentWillMount() {
this.case = this.props.store.case
this.setState({refresh: false})
}
setPwd(e) {
// console.log(e)
this.case.pwd = e.target.value
}
submit() {
console.log(this.props.caseId)
this.setState({refresh: true})
}
render() {
return (
<Container>
<div>{this.state.refresh}</div>
{ (this.state.refresh) && <Redirect refresh={true} to={'/cases/' + this.props.caseId}></Redirect>}
<br />
<Grid columns="three">
<Grid.Row>
<Grid.Column key={2}>
<Form>
<label>Enter Password</label>
<input placeholder="empty" type="text" onChange={this.setPwd} value={this.case.pwd}></input>
<Button name="Save" color="green" size="mini"
style={{marginTop:'1em'}}
onClick={this.submit}>
Submit
</Button>
</Form>
</Grid.Column>
</Grid.Row>
</Grid>
</Container>
)
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…