How do you create nested routes?
To create nested routes, place a <Route /> inside another route's component.
Example:
import { BrowserRouter as Router, Route, Switch, Link } from
'react-router-dom';
function App() {
return (
<Router>
<div>
<nav>
<Link to="/about/team">Team</Link>
<Link to="/about/company">Company</Link>
</nav>
<Switch>
<Route exact path="/about" component={About} />
<Route path="/about/team" component={Team} />
<Route path="/about/company" component={Company} />
</Switch>
</div>
</Router>
);
}
function About() {
return <h2>About Page</h2>;
}
function Team() {
return <h3>Team Page</h3>;
}
function Company() {
return <h3>Company Page</h3>;
}