- Introduction Get ready to explore React Router! React Router is a powerful library for handling navigation in your React apps. Let’s dive in with Geek and Gal as they make routing a breeze with some hilarious interactions.
- Installing React Router
npm install react-router-dom
- Basic Routing
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import Home from './Home';
import About from './About';
function App() {
return (
<Router>
<nav>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
</ul>
</nav>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
</Router>
);
}
- Conclusion
React Router makes handling navigation in your React apps a piece of cake! With the
react-router-dom
package, you can use theBrowserRouter
,Route
, andLink
components to create dynamic and flexible routing. Now, you’re ready to build amazing navigations in your React apps! 😃