历史记录推送不更新新数据

时间:2018-10-28 11:30:36

标签: javascript reactjs react-native

使用基本的reactjs应用程序,更新我的表单(页面名称:/ update /:id)后,我想推送到另一个名为view(页面名称:/ view /:id)的页面,不幸的是我的新更新未反映在 / view /:id ,它显示的是旧数据

这是我的 / update /:id 代码

  handleSubmit(e) {

    e.preventDefault();

    const data = {
            title: this.state.title
        }
        axios.post('http://localhost:3001/user/bio/update/'+this.props.match.params.id, data)
        .then(res => console.log(res.data));
        this.setState({
            title: ''

        })
        this.props.history.push('/view/' + this.props.match.params.id);
        //this.props.location.state('/view/' + this.props.match.params.id);


    }

//路由器

render() {
    return (

       <Router>   
          <Switch>
            <Route exact path='/create' component={ViewId} />
            <Route path="/view/:id" component={ViewId}/>
            <Route path="/bio/update/:id" component={BioUpdateById}/>
          </Switch>
      </Router>
    );
  }
}

1 个答案:

答案 0 :(得分:0)

我不知道您的应用程序是如何设置的,但是我将使用Redux来存储POST响应并在/ view /:id组件路由中使用它。

对于直接进入此路线的用户,在/ view /:id的componentDidMount上有一个GET请求。为了避免不必要的请求(在视图中显示),您可以检查以前是否在Redux上收到过该请求。

但是,如果要保持简单,只需在视图上添加GET请求即可。

相关问题