npm install react-router-dom
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
Create your different components that will represent different pages in your application. For example, you can create a Home component and a About component.
Inside your App component, wrap your entire application with the Router component:
function App() {
return (
<Router>
<div className="App">
{/* Your routes go here */}
</div>
</Router>
);
}
function App() {
return (
<Router>
<div className="App">
<Switch>
<Route path="/" exact component={Home} />
<Route path="/about" component={About} />
</Switch>
</div>
</Router>
);
}
import { Link } from 'react-router-dom';
function Home() {
return (
<div>
<h1>Home Page</h1>
<Link to="/about">Go to About Page</Link>
</div>
);
}
export default Home;