【问题标题】:react-router url change but had to double click "Link" component for ui to changereact-router url更改,但必须双击“链接”组件才能更改ui
【发布时间】:2017-01-31 16:47:25
【问题描述】:

第一次加载内容正确显示时,单击链接会更改 URL,但视图仍然相同。我必须单击两次才能更改视图。

我的路由器

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

【问题讨论】:

  • 就是这样,因为您正在使用“旧”道具。尝试使用最新的类似这样的东西。componentWillUpdate(props) { const { dispatch, params: { courseName, splat } } = props; dispatch(actions.fetchChapter(courseName, splat));
  • 谢谢@dlopez!

标签: reactjs redux react-router


【解决方案1】:

正如@dlopez 指出的,我必须使用传入的道具。

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

【讨论】:

    猜你喜欢
    • 2020-05-06
    • 1970-01-01
    • 2018-04-23
    • 2021-09-01
    • 2020-08-16
    • 2018-12-29
    • 2021-08-10
    • 2019-11-23
    • 1970-01-01
    相关资源
    最近更新 更多