0
0
Reactframework~10 mins

Client-side routing concept in React - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Client-side routing concept
User clicks a link
Intercept click event
Update URL in browser without reload
React Router matches URL to component
Render matched component
Display new page content
Wait for next user interaction
This flow shows how client-side routing intercepts link clicks, updates the URL, and renders components without reloading the page.
Execution Sample
React
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';

function App() {
  return (
    <BrowserRouter>
      <nav><Link to="/about">About</Link></nav>
      <Routes>
        <Route path="/about" element={<About />} />
      </Routes>
    </BrowserRouter>
  );
}

function About() {
  return <h1>About Page</h1>;
}
This React code sets up client-side routing with a link to an About page that renders without a full page reload.
Execution Table
StepUser ActionBrowser URLReact Router ActionRendered ComponentPage Reload
1Initial loadhttp://localhost/Match '/' route (default)Home or default componentNo
2User clicks 'About' linkhttp://localhost/aboutMatch '/about' routeAbout componentNo
3User clicks browser backhttp://localhost/Match '/' routeHome or default componentNo
4User enters URL manuallyhttp://localhost/contactMatch '/contact' route or 404Contact or NotFound componentNo
5User refreshes pagehttp://localhost/contactServer handles routeFull page reloadYes
💡 Client-side routing stops reloading pages except on manual refresh or unknown routes.
Variable Tracker
VariableInitialAfter Step 2After Step 3After Step 4Final
currentURLhttp://localhost/http://localhost/abouthttp://localhost/http://localhost/contacthttp://localhost/contact
renderedComponentHome or defaultAboutHome or defaultContact or NotFoundContact or NotFound
pageReloadfalsefalsefalsefalsetrue (on refresh)
Key Moments - 3 Insights
Why doesn't clicking a Link cause the whole page to reload?
Because React Router intercepts the click event and updates the URL and component rendering internally without triggering a full browser reload, as shown in execution_table step 2.
What happens when the user refreshes the page on a client-side route?
The browser sends a request to the server for that URL, causing a full page reload, unlike client-side navigation. This is shown in execution_table step 5.
How does React Router know which component to show?
It matches the current URL to the defined routes and renders the corresponding component, as seen in execution_table steps 2 and 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what component is rendered after the user clicks the 'About' link?
AHome component
BAbout component
CContact component
DNotFound component
💡 Hint
Check the 'Rendered Component' column at Step 2 in the execution_table.
At which step does a full page reload occur according to the execution_table?
AStep 5
BStep 3
CStep 2
DStep 4
💡 Hint
Look at the 'Page Reload' column for the step where it says 'Yes'.
If the user manually enters a URL that matches no route, what will React Router do?
AReload the page
BRender the Home component
CRender the NotFound component
DShow a blank page
💡 Hint
See Step 4 in the execution_table where unmatched routes render NotFound.
Concept Snapshot
Client-side routing lets React apps change pages without reloading.
Use <BrowserRouter> to wrap your app.
Use <Link> to change URL without reload.
<Routes> and <Route> match URL to components.
Browser URL updates but page stays loaded.
Refresh causes full reload from server.
Full Transcript
Client-side routing in React means the app changes what you see without reloading the whole page. When you click a link, React Router catches that click, changes the URL in the browser, and shows the right component. This happens fast because the page does not reload. The flow starts when the user clicks a link, React Router updates the URL, matches it to a component, and renders it. The execution table shows steps like initial load, clicking links, and refreshing. Variables like currentURL and renderedComponent change as you navigate. Key points include why clicking a Link doesn't reload the page, what happens on refresh, and how React Router matches URLs. The quiz checks understanding of which component shows and when reloads happen. Remember, client-side routing improves user experience by avoiding full page reloads.