Reactjs 导航到某个路径后清除位置状态
我正在使用react routerReactjs 导航到某个路径后清除位置状态,reactjs,react-router,Reactjs,React Router,我正在使用react routerbrowserHistory导航到路径 browserHistory.push({ pathname: '/mycomponent', state: { someValue: 'value'}, }); 因此,这将导航到mycomponent。我一接触mycomponent,就想清除键someValue。因此,当我刷新页面时,它将不包含该值 export class myComponent extends component { component
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
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: {}
});
}
}
刷新页面后,afaik
someValue
将不会处于位置状态。所以你不需要手动删除它。@TharakaWijebandara-即使在页面刷新后我也能看到它。。