加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – 导航到某个路径后清除位置状态

发布时间:2020-12-15 20:42:51 所属栏目:百科 来源:网络整理
导读:我正在使用react-router browserHistory导航到路径. browserHistory.push({ pathname: '/mycomponent',state: { someValue: 'value'},}); 所以这将导航到mycomponent.一旦我到达mycomponent,我想清除关键someValue.所以当我刷新页面时,它不会包含该值. expor
我正在使用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: {}
       });
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读