我正在使用react-router browserHistory导航到路径.
browserHistory.push({ pathname: '/mycomponent',state: { someValue: 'value'},});
所以这将导航到mycomponent.一旦我到达mycomponent,我想清除关键someValue.所以当我刷新页面时,它不会包含该值.
export class myComponent extends component { componentWillMount() { const value = this.props.location.state.someValue; // clear state.someValue from history } }
任何帮助,将不胜感激.
我认为您可以使用browserHistory替换方法将历史状态替换为没有someValue定义的新状态:
export class myComponent extends component { componentWillMount() { const value = this.props.location.state.someValue; // clear state.someValue from history browserHistory.replace({ pathname: '/mycomponent',state: {} }); } }