duw*_*ise 9 reactjs react-router
我正在使用react-router browserHistory导航到路径.
browserHistory.push({
pathname: '/mycomponent',
state: { someValue: 'value'},
});
Run Code Online (Sandbox Code Playgroud)
所以这将导航到mycomponent.一旦我到达我的组件我想清除钥匙someValue.所以当我刷新页面时,它不会包含该值.
export class myComponent extends component {
componentWillMount() {
const value = this.props.location.state.someValue;
// clear state.someValue from history
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
Bar*_*icz 18
我认为您可以使用browserHistory replace方法将历史状态替换为someValue未定义的新状态:
export class myComponent extends component {
componentWillMount() {
const value = this.props.location.state.someValue;
// clear state.someValue from history
browserHistory.replace({
pathname: '/mycomponent',
state: {}
});
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7007 次 |
| 最近记录: |