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