我正在使用反应路由器browserHistory
导航到路径。
browserHistory.push({
pathname: '/mycomponent',
state: { someValue: 'value'},
});
所以这将导航到 mycomponent。一旦我到达我的组件,我想清除密钥someValue
。这样当我刷新页面时它就不会包含该值。
export class myComponent extends component {
componentWillMount() {
const value = this.props.location.state.someValue;
// clear state.someValue from history
}
}
任何帮助,将不胜感激。
我认为你可以使用 browserHistoryreplace
用新状态替换历史状态的方法,无需someValue
定义:
export class myComponent extends component {
componentWillMount() {
const value = this.props.location.state.someValue;
// clear state.someValue from history
browserHistory.replace({
pathname: '/mycomponent',
state: {}
});
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)