In traditional server-rendered websites, navigation between URLs triggers a full HTTP round-trip: the browser requests a new page, receives a fresh HTML document, and completely tears down the existing page.
In a modern Single-Page Application (SPA), client-side routing intercepts user navigation clicks. Instead of requesting a new HTML file from the server:
window.history.pushState).React Router is the standard routing library for the React ecosystem. It allows developers to bind components to URL paths declaratively.
| Component / Hook | Role & Responsibility |
|---|---|
createBrowserRouter | Modern recommended router setup utilizing the DOM History API. |
RouterProvider | Root component that provides routing context to the entire application. |
<Routes> & <Route> | Declarative route mapping primitives used in JSX configurations. |
<Link> | Client-side anchor replacement that updates the URL without page reloads. |
<NavLink> | Enhanced <Link> that knows when it is active (applies active CSS classes). |
<Outlet> | Placeholder slot inside parent layouts where child route components render. |
<a href="..."> for Internal LinksUsing standard <a href="/courses"> tags in a React application causes the browser to execute a full page reload, destroying all in-memory React state, resetting Context stores, and defeating the entire purpose of a Single-Page Application!
Always use <Link to="..."> or <NavLink to="..."> for internal routes.
<a href="/path"> tags for internal navigation in an SPA?<Link> and <NavLink> in React Router?<Route> specifies the React component to render?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| React Hook Form Basics and Schema Validation | Defining Routes, Route Layouts, and Outlets |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.