从反应路由器我的链接标签不会改变我的
问题描述:
页
我有以下结构:从反应路由器我的链接标签不会改变我的
<CategoryRecipesList>
<Title> Recipes for {this.props.category} </Title>
<Mesh> You can also click on : {categoryList.map(el => <Link to={'categories/' + el}>{el}</Link>} </Mesh>
<Grid>
recipes.map((s, i) => <Card {...s}/>)
</Grid>
</CategoryRecipesList>
我有获取recipes
根据category
PARAM列表中的所属分类组件上的构造函数。
当我点击<Link/>
标记时,标题和网址更新,但不是网格中的<Card>
。
有没有人有任何线索?
答
我找到了解决方案。我需要考虑到网格中的卡片取决于父组件中的道具()。因此,如果我从点击<Mesh/>
来更改网址,则需要使用ComponentWillReceiveProps(newProps)
方法,比较这个.props.category是否因比较而改变(this.props.category
和newProps.category
)。如果是这样,我需要取出新卡准确显示。现在运作良好。
在<CategoryRecipesList>
组分:
componentWillReceiveProps(nextProps) {
if (this.props.params.category_type !== nextProps.params.category_type) {
this.category = nextProps.params.category_type
this.props.fetchRecipesByDevice(this.category)
}
}
感谢。我编辑了我的问题,以更加明确地解释我的斗争。 –
@StanAmsellem我更新了我的答案。尝试包装_Card_组件。 –
不幸的是它不起作用 –