- Introduction In this section, we’ll learn how to navigate between pages using React Router. Geek and Gal will guide you through the process, making it easy to understand for beginners and advanced users alike!
- Step 1: Using the Link Component
- Step 2: Creating Navigation Links
import { Link } from 'react-router-dom';
function Navigation() {
return (
<nav>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about">About</Link>
</li>
</ul>
</nav>
);
}
- Step 3: Adding the Navigation Component
import Navigation from './Navigation';
function App() {
return (
<div>
<Navigation />
{/* ... other components and routes ... */}
</div>
);
}
- Conclusion
Navigating between pages in a React app is simple with React Router! Just follow these steps: use the
Link
component to create navigation links, specify the paths using theto
prop, and add the navigation component to your app. Now you can effortlessly switch between pages in your React apps! 😎