2017-04-19 28 views
1

我有以下結構:從反應路由器我的鏈接標籤不會改變我的

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

有沒有人有任何線索?

回答

0

我找到了解決方案。我需要考慮到網格中的卡片取決於父組件中的道具()。因此,如果我從點擊<Mesh/>來更改網址,則需要使用ComponentWillReceiveProps(newProps)方法,比較這個.props.category是否因比較而改變(this.props.categorynewProps.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) 
    } 
    } 
0

您可能正在查看Update Blocking。嘗試使用withRouter包裝卡組件。

export default withRouter(Card) 
+0

感謝。我編輯了我的問題,以更加明確地解釋我的鬥爭。 –

+0

@StanAmsellem我更新了我的答案。嘗試包裝_Card_組件。 –

+0

不幸的是它不起作用 –

相關問題