react-router url 更改但必须双击“链接";ui 改变的组件 [英] react-router url change but had to double click "Link" component for ui to change

查看:38
本文介绍了react-router url 更改但必须双击“链接";ui 改变的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一次加载时,内容显示正确,点击链接会改变网址,但视图还是一样.我必须单击两次才能更改视图.

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.

我的路由器

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')
);

我在章节组件中的调度

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

推荐答案

正如@dlopez 所指出的,我不得不使用传入的 props.

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));
}

这篇关于react-router url 更改但必须双击“链接";ui 改变的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆