All topics
Routingbeginner

React Router Fundamentals

Learn the core building blocks of React Router: routes, links, and how client-side navigation avoids full page reloads.

React Router is the most widely used client-side routing library for React, letting a single-page application render different components based on the current URL without triggering a full page reload from the server. Its core building blocks are <BrowserRouter> (wraps the app and hooks into the browser's History API), <Routes>/<Route> (declaratively map URL paths to components), and <Link> (renders navigable anchor tags that update the URL without a full reload).

React Router is like an usher inside a large building who directs you to different rooms based on which door you asked for, all without you ever having to leave and re-enter the building itself (a full page reload) — you just walk to a different room while staying inside the same building.

Key Concepts

1
Unlike a traditional multi-page site where every navigation requests a fresh HTML document from the server, React Router intercepts navigation, updates the browser's URL via the History API (pushState), and re-renders only the parts of the React tree whose matched route changed — giving the snappy, app-like feel associated with single-page applications.
pushState
2
<Link to="/about"> should always be used instead of a plain <a href="/about"> for internal navigation, since a plain anchor tag triggers a full browser page load, discarding all client-side state and defeating the purpose of a client-rendered SPA. <NavLink> extends <Link> with automatic 'active' styling based on whether its target matches the current URL.
<Link to="/about"><a href="/about"><NavLink><Link>
3
Interviewers commonly ask candidates to explain what actually happens in the browser when a <Link> is clicked versus a plain anchor tag, expecting an answer that covers History API usage and the avoidance of a full document reload.
<Link>