I am trying to render content in an element separate to the menu nav element, but it keeps rendering in the same element as the menu bar. I tried to separate the links from the router but then got errors.
Here is my Router component, which I am importing into my entry file:
import React from 'react';
import ReactDOM from 'react-dom';
import ReactDOMServer from 'react-dom/server';
import {BrowserRouter as Router, Route, Link, StaticRouter} from 'react-router-dom';
import Home from './Home.jsx';
import About from './About.jsx';
import BlogList from './BlogList.jsx';
const Routes = () => (
<Router>
<div>
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to="/about">About</Link></li>
<li><Link to="/blog">Blog</Link></li>
</ul>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/blog" component={BlogList} />
</div>
</Router>
)
export default Routes;
ReactDOM.render((
<Routes />
), document.getElementById('main-nav'))
My question is:
How do render the content from the Home, About and Blog components in a seperate element so they don't render inside "#main-nav"? A route can only have 1 child element.
If I try to add the routes in their own div container I get errors. If I wrap a nav element to the ul, I get an error.
Ideally, I want something like this:
<nav id="main-nav">
<div>
<ul>
<li a href="/">Home</a></li>
<li a href="/about">About</a></li>
<li a href="/blog">Blog</a></li>
</ul>
</div>
</nav>
<div id="content">
Home / ABout / Blog Content in here
</div>
/matches every single URL in your app. Use theexactprop to only match the root path. - Andrew Li