简体   繁体   English

有条件地呈现DataSearch组件

[英]Conditionally render DataSearch component

I've built a search ui using ReactiveSearch components and it works great! 我使用ReactiveSearch组件构建了一个搜索ui,效果很好! Now I'm trying to figure out how I can conditionally show the DataSearch component that I have in my Navbar based on the route/view that is being displayed. 现在,我试图根据显示的路线/视图来确定如何有条件地显示导航栏中的DataSearch组件

For example on my homepage. 例如在我的主页上。 I have a big DataSearch component search form in a jumbotron and I don't need/want the the DataSearch component that also displays in the Navbar. 我在超大型飞行器中有一个很大的DataSearch组件搜索表单,不需要/也不需要在导航栏中显示的DataSearch组件。

I've looked at this and this but I'm not sure how to implement those in the context of the DataSearch component from ReactiveSearch. 我看着这个这个 ,但我不知道如何实现那些从ReactiveSearch的DataSearch组件的上下文。

UPDATE : 更新

So I've been looking into how I can grab the url from React Router (v4) and it seems I can get it from doing this: 所以我一直在研究如何从React Router(v4)中获取url,看来我可以从中获取它:

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

So then I thought I could use something like location !== '/' && DataSearch but that doesn't work. 因此,我以为我可以使用诸如location !== '/' && DataSearch但这不起作用。

Have you tried any of these? 你有没有尝试过这些?

{condition && <DataSearchComponent/>}

or 要么

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM