<Link to="/about">About</Link>React Router's prevents the browser's default full page reload. Instead, it changes the URL and renders the new component inside the app, making navigation fast and smooth.
In React Router v6, the element prop is used to specify the component to render. The other props were used in older versions.
import { useNavigate, Routes, Route } from 'react-router-dom'; function App() { const navigate = useNavigate(); return ( <> <button onClick={() => navigate('/dashboard')}>Go Dashboard</button> <Routes> <Route path="/" element={<h1>Home</h1>} /> <Route path="/dashboard" element={<h1>Dashboard</h1>} /> </Routes> </> ); }
The navigate('/dashboard') call changes the URL to '/dashboard' and React Router renders the matching route's element, which is <h1>Dashboard</h1>.
import { BrowserRouter, Routes, Route } from 'react-router-dom'; function App() { return ( <BrowserRouter> <Route path="/about" element={<About />} /> </BrowserRouter> ); }
In React Router v6, Route components must be wrapped inside a Routes component. Without Routes, the route will not render.
Client-side routing updates the URL and page content without reloading the whole page, which makes the app feel faster and more responsive.
