- Introduction Today, we’ll learn about React Router! React Router is a powerful library that handles navigation in React apps. Join Geek and Gal as they have fun exploring the basics of React Router in a way that’s easy to understand for beginners and advanced users alike.
- 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 breeze! With the
react-router-dom
package, you can easily use theBrowserRouter
,Route
, andLink
components to create dynamic and flexible routing. Now you’re ready to build amazing navigation in your React apps! 😃