【发布时间】:2017-06-25 09:18:23
【问题描述】:
当从 indexRoute 更改为路径为 ':topic' 的 Route 时,页面保持不变。
我的路线如下所示:
ReactDOM.render(
<Provider store={store}>
<Router history={browserHistory}>
<Route path='/' addHandlerKey={true} component={App}>
<IndexRoute component={ArticleList} />
<Route path='/:topic' component={ArticleList} />
<Route path='/:id' component={Article} />
</Route>
</Router>
</Provider>, document.getElementById('app'));
文章列表如下所示:
const _ArticleList = React.createClass({
componentWillMount () {
this.props.fetchArticles();
},
render () {
return (
<div id='ArticleList' className='box'>
{this.props.articles.map(function (article, i) {
return <ArticleCard id={article._id} key={i} title={article.title} votes={article.votes} />;
})}
</div>
);
}
当我导航到路线然后刷新页面时,它会更改为我想要的,而不是直接导航到它时。
需要明确的是,url 正在改变(感谢 App 组件),所以 params.topic 正在改变,但组件没有重新渲染,所以 componentWillMount 没有被触发。 (已经尝试过 componentWillReceiveProps 但这没有用)
【问题讨论】:
标签: reactjs react-router