React Router & Navigation (v6)
Introduction
React Router v6 is the latest version of the routing library that provides declarative routing for React
applications.
Setting Up React Router
Install it using npm install react-router-dom and wrap your app with BrowserRouter.
Routes and Route
Define navigation paths using the Routes and Route components.
<Routes>
<Route path='/' element={<Home />} />
<Route path='/about' element={<About />} />
</Routes>
useNavigate Hook
useNavigate allows programmatic navigation to other routes.
const navigate = useNavigate();
<button onClick={() => navigate('/home')}>Go Home</button>
Nested Routes
Nested routes allow building modular and hierarchical routing structures.
Summary
React Router enables seamless single-page application navigation and dynamic URL
management.