Reputation: 2132
I have that type of structure:
<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>
Navbar & Footer should be on every pages, instead RegisterPage & LoginPage.
How Can I hide <Navbar/>
<Footer/>
in a different way than adding to each page, is this a recommended practice?
Upvotes: 0
Views: 156
Reputation: 1866
You can use some default state, setting something like registered: false
In your parent component:
this.state = { registered: false };
Then, inside both <Navbar/>
and <Footer/>
, check if registered is false or true:
if(!this.state.registered){
// Hide component
} else {
// Show component
}
Of course, once the user is registered, you'll need to set registered as true
Upvotes: 2