react-router url change but had to double click “L

2019-09-17 08:50发布

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条回答
祖国的老花朵
2楼-- · 2019-09-17 09:20

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));
}
查看更多
登录 后发表回答