Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 错误处理后如何刷新反应页面_Reactjs - Fatal编程技术网

Reactjs 错误处理后如何刷新反应页面

Reactjs 错误处理后如何刷新反应页面,reactjs,Reactjs,我有以下资料: <ErrorBoundary> <NavBar /> </ErrorBoundary> <ErrorBoundary> <Switch> <Route exact path="/" component={mainPage} /> <Route exact path="/" component=

我有以下资料:

<ErrorBoundary>
      <NavBar />
</ErrorBoundary>


<ErrorBoundary>
        <Switch>
          <Route exact path="/" component={mainPage} />
          <Route exact path="/" component={buyerPage} />
          <Route exact path="/" component={sellerPage} />
        </Switch>
</ErrorBoundary>

<ErrorBoundary>
      <Footer />
</ErrorBoundary>

错误发生在buyerPage中:http://localhost:3000/#/buyer. 但是导航栏和页脚组件仍然加载(我想要的)。当我从导航栏点击卖家时,页面链接会转到http://localhost:3000/#/seller 但是错误仍然会出现,除非我手动刷新页面(然后它会显示卖家页面的内容)

当我们点击离开错误页面(在我的例子中是买方页面)时,有没有一种方法可以自动刷新页面

这是我的错误边界代码:

render() {
        if(this.state.hasError){
            return (
                <div style={errorStyle}>
                     <h2>Something went wrong</h2>
                </div>
            )
        }
        else{
            //refers to the component we are actually rendering
            return (this.props.children);
        }
    }
render(){
if(this.state.hasError){
返回(
出了点问题
)
}
否则{
//指我们实际渲染的组件
返回(本.道具.儿童);
}
}

错误边界内
清除组件更新时的
hasrerror

componentDidUpdate(previousProps, previousState) {
    if (previousProps.children!==this.props.children)
        this.setState({hasError: false});
}