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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -