React:无法使用 react-router 找到阻塞组件

React: Cant find blocking component using react-router

我认为这是由于我更新位置的方式所致,但我不确定。

我的做法是这样的:

<Route render={props => <Somecomponent location={props.location} /> } />

然后在 Somecomponent 中我执行以下操作:

someAction(context){
   globals.context = context
   // some other stuff that triggers an event ELSEWHERE
   // that event will update the location via this context variable
}

...
render(){
 return <Route render={context => {
       return <div onClick={() => this.someActionThatChangesLocation(context)}

}}/> }

其他地方:

someEvent(){
   globals.context.history.push("/newlocation")
}

发生的情况是,URL 得到了更新,但视图没有得到更新。所以我坚持旧观点。

如何找出阻止渲染的组件?

我添加了 location 道具,因为我读到它会触发重新渲染但它不起作用,所以我假设阻塞组件是不同的。

我不确定如何进一步调试它..

所以我不确定现在到底是什么解决了这个问题,因为在它最终起作用之前我做了很多改变。

  1. 我的 App 组件现在包装成这样:

    class AppWrapper extends Component { render() { return <Router> <Route component={withRouter(App)} /> </Router> } }

  2. 我不再使用 globals.context 因为现在我可以在 App.js 组件

  3. 中访问 this.props.history
  4. 我确定那是我应用程序中唯一的路由器。在我的应用程序和 Wrapper 中都有 Router 组件之前,我认为由于某种原因阻止了更新,但不确定。