react-router url change but had to double click “Link” component for ui to change

做~自己de王妃 提交于 2019-12-25 08:05:13

问题


When loading for the first time the content is displayed correctly, clicking a link will change the URL but the view still the same. I had to click twice for the view to change.

My router

render(
<Provider store={store}>
    <Router history={browserHistory}>
        <Route path="/:courseName/**" component={components.app}>
            <IndexRoute components={{
                sidebar: containers.sidebar,
                chapter: containers.chapter
            }} />
        </Route>
    </Router>
</Provider>,
document.getElementById('container')
);

My dispatch inside the chapter component

componentWillUpdate() {
    const { dispatch, params: { courseName, splat } }  = this.props;
    dispatch(actions.fetchChapter(courseName, splat));

回答1:


As @dlopez pointed out, I had to use the incoming props.

componentWillReceiveProps(nextProps) {
    console.log("In erhe");
    const { dispatch, params: { courseName, splat } }  = nextProps;
    dispatch(actions.fetchChapter(courseName, splat));
}


来源:https://stackoverflow.com/questions/41962950/react-router-url-change-but-had-to-double-click-link-component-for-ui-to-chang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!