React Router is the standard library for routing in React. It enables the creation of complex, multi-page experiences within a Single Page Application.
1The SPA Paradigm
In a traditional website, clicking a link sends a request to the server, which responds with a brand new HTML file. This causes a 'white flash' and a full page reload. In a React SPA with React Router, the 'Link' component intercept the click, prevents the browser from loading a new page, and instead tells React to swap out the visible components. This makes navigation feel instant and app-like.
2Dynamic Routing
Dynamic routing is what allows a single component to serve thousands of different pages (like user profiles or product pages). By using the ':param' syntax in your routes, you create 'holes' in the URL that React Router fills with actual data. The useParams hook is your tool for reaching into the URL and grabbing that data to use in your component's logic.
