隐藏特定页面上的组件
Hide components on specific page
我有那种结构:
<Router onUpdate= {scrollToTop} history={history}>
<div>
<Navbar/>
<ScrollToTopRoute exact path="/" component={home} />
<ScrollToTopRoute path="/fund" component={fund} />
<ScrollToTopRoute path="/browseideas" component={browseideas} />
<ScrollToTopRoute path="/earnwithus" component={earnwithus} />
<ScrollToTopRoute path="/register" component={RegisterPage} />
<ScrollToTopRoute path="/login" component={LoginPage} />
<ScrollToTopRoute path="/idea" component={idea} />
<ScrollToTopRoute path="/lightning" component={Lightning} />
<ScrollToTopRoute path="/storm" component={Storm} />
<ScrollToTopRoute path ="/increase" component ={increase}/>
<ScrollToTopRoute path ="/policy" component ={policyprivacy}/>
<PrivateRoute path ="/homepage" component ={homepage}/>
<PrivateRoute path ="/activehedges" component ={ActiveHedges}/>
<PrivateRoute path ="/userprofile" component ={UserProfile}/>
<PrivateRoute path ="/myfunds" component ={MyFunds}/>
<PrivateRoute path ="/deposit" component ={deposit}/>
<PrivateRoute path ="/withdraw" component ={withdraw}/>
<Footer/>
</div>
</Router>
导航栏和页脚应该在每个页面上,而不是 RegisterPage 和 LoginPage。
如何隐藏 <Navbar/>
<Footer/>
以不同于添加到每个页面的方式,这是推荐的做法吗?
您可以使用一些默认 state,设置类似 registered: false
在你的父组件中:
this.state = { registered: false };
然后,在<Navbar/>
和<Footer/>
中,检查registered是false还是true:
if(!this.state.registered){
// Hide component
} else {
// Show component
}
当然,一旦用户注册了,你就需要将registered设置为true
我有那种结构:
<Router onUpdate= {scrollToTop} history={history}>
<div>
<Navbar/>
<ScrollToTopRoute exact path="/" component={home} />
<ScrollToTopRoute path="/fund" component={fund} />
<ScrollToTopRoute path="/browseideas" component={browseideas} />
<ScrollToTopRoute path="/earnwithus" component={earnwithus} />
<ScrollToTopRoute path="/register" component={RegisterPage} />
<ScrollToTopRoute path="/login" component={LoginPage} />
<ScrollToTopRoute path="/idea" component={idea} />
<ScrollToTopRoute path="/lightning" component={Lightning} />
<ScrollToTopRoute path="/storm" component={Storm} />
<ScrollToTopRoute path ="/increase" component ={increase}/>
<ScrollToTopRoute path ="/policy" component ={policyprivacy}/>
<PrivateRoute path ="/homepage" component ={homepage}/>
<PrivateRoute path ="/activehedges" component ={ActiveHedges}/>
<PrivateRoute path ="/userprofile" component ={UserProfile}/>
<PrivateRoute path ="/myfunds" component ={MyFunds}/>
<PrivateRoute path ="/deposit" component ={deposit}/>
<PrivateRoute path ="/withdraw" component ={withdraw}/>
<Footer/>
</div>
</Router>
导航栏和页脚应该在每个页面上,而不是 RegisterPage 和 LoginPage。
如何隐藏 <Navbar/>
<Footer/>
以不同于添加到每个页面的方式,这是推荐的做法吗?
您可以使用一些默认 state,设置类似 registered: false
在你的父组件中:
this.state = { registered: false };
然后,在<Navbar/>
和<Footer/>
中,检查registered是false还是true:
if(!this.state.registered){
// Hide component
} else {
// Show component
}
当然,一旦用户注册了,你就需要将registered设置为true