簡體   English   中英

有條件地呈現DataSearch組件

[英]Conditionally render DataSearch component

我使用ReactiveSearch組件構建了一個搜索ui,效果很好! 現在,我試圖根據顯示的路線/視圖來確定如何有條件地顯示導航欄中的DataSearch組件

例如在我的主頁上。 我在超大型飛行器中有一個很大的DataSearch組件搜索表單,不需要/也不需要在導航欄中顯示的DataSearch組件。

我看着這個這個 ,但我不知道如何實現那些從ReactiveSearch的DataSearch組件的上下文。

更新

所以我一直在研究如何從React Router(v4)中獲取url,看來我可以從中獲取它:

componentWillReceiveProps(nextProps) {
                if (nextProps.location !== this.props.location) {
...

因此,我以為我可以使用諸如location !== '/' && DataSearch但這不起作用。

你有沒有嘗試過這些?

{condition && <DataSearchComponent/>}

要么

{condition ? <DataSearchComponent/> : <OtherComponent/>}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM