The point of using react-router
is generally to have page not refreshed as user navigates.
If you bring your nav links inside the react app you will get to experience single page application without refreshing the page.
Otherwise, you can have something like this:
import React from "react";
import ReactDOM from "react-dom";
import { Route, BrowserRouter as Router } from "react-router-dom";
const App = () => <div>Home Page</div>;
const App2 = () => <div>Page 2</div>;
const routing = (
<Router>
<div>
<Route exact path="/" component={App} />
<Route path="/page2" component={App2} />
</div>
</Router>
);
ReactDOM.render(routing, document.getElementById("react-root"));
But better way is something like this:
const App = () => <div>Home Page</div>;
const App2 = () => <div>I am Page 2</div>;
const routing = (
<Router>
<div class="menu">
<Link to="/">Home Page</Link>
<Link to="/page2">Page 2</Link>
</div>
<div>
<Route exact path="/" component={App} />
<Route path="/page2" component={App2} />
<Route path="/page3" component={App} />
</div>
</Router>
);
ReactDOM.render(routing, document.getElementById("react-root"));
Here is the code sandbox link where you can see the difference between two
https://codesandbox.io/s/holy-wind-olex5?fontsize=14&hidenavigation=1&theme=dark