reactjs - React Router DOM — How to include a navigation bar on every page? -


i have code in app.js component:

render() {         return (             <div>                 <navbar/>                 <browserrouter>                     <switch>                         <route exact path="/" component={home}/>                         <route path="/about" component={about} />                                                  <route path="*" render={() => <redirect to="/" />} />                     </switch>                 </browserrouter>             </div>         );     } 

now tried include link component in 1 of other components, figured out browserrouter has root element of app.js component, in order work. wonder how go making route element, if still want include navigation bar on every page.

you should able place outside <switch> component.

<browserrouter>     <div>         <navbar/>         <switch>             <route exact path="/" component={home}/>             <route path="/about" component={about} />                                      <route path="*" render={() => <redirect to="/" />} />         </switch>     </div> </browserrouter> 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -