1
<Provider store = {store}>
    <Router history = {history} >
       <section>
            <HeaderWithRouter>
                <Route exact path = "/admin" component={Admin}/>
                <Route exact path = "/deal" component={FormDeal}/>
                <Route exact path="/chart" component={Mycharts}/>
                <SubHeaderWithRouter>
                    <Route exact path="/dealview" component={FinalTable}/>
                    <Route exact path = "/mandate" component={Mandate}/>
                </SubHeaderWithRouter>  
            </HeaderWithRouter>
            <Footer/>
       </section>
  </Router>
  </Provider>

I need to render SubHeaderWithRouter only for the sub routes specified inside it i.e FinalTable and Mandate. Currently SubHeaderWithRouter is rendered for every route.

2
  • I don't really understand your question! Commented Sep 19, 2017 at 10:38
  • see @cdaiga if my route is /admin then i dont want SubHeaderWithRouter to get rendered. i want to render SubHeaderWithRouter only for /dealview and /mandate Commented Sep 19, 2017 at 10:39

1 Answer 1

1

You can specify the regex path for which you want to render the SubHeaderWithRouter component

<Provider store = {store}>
    <Router history = {history} >
       <section>
            <HeaderWithRouter>
                <Route exact path = "/admin" component={Admin}/>
                <Route exact path = "/deal" component={FormDeal}/>
                <Route exact path="/chart" component={Mycharts}/>
                <Route path="/(dealview|mandate)" component={SubHeaderWithRouter}/>
            </HeaderWithRouter>
            <Footer/>
       </section>
  </Router>

and then inside it, specify the actual Routes like

render() {
    return (
         <div>
             {/*other things*/}
             <Route exact path="/dealview" component={FinalTable}/>
             <Route exact path = "/mandate" component={Mandate}/>
         </div>
     )

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.