Skip to content
tezvyn:
Menu

Client-Side Routing: No More Full Page Reloads

Source: Wikipedia: Single-page applicationEasyHow cards are made

Client-side routing fakes page navigation. Instead of fetching new HTML from a server, it just shows or hides components already loaded, making transitions feel instant. This powers single-page apps (SPAs).

Why it exists

Traditional websites required a full page load from the server for every navigation. This round-trip created a noticeable delay, making web applications feel slow and clunky compared to native desktop or mobile apps. Client-side routing was created to eliminate this delay and provide a faster, more fluid user experience.

The mental model

Think of your web app as a single program running in the browser. Instead of having multiple HTML files for different pages, you have one index.html file that acts as the stage. Client-side routing is the stage manager, deciding which "scenes" (components) to show or hide on that stage based on the URL, without ever asking the server for a new stage.

How it works

When a user clicks a link, a client-side router intercepts the browser's default navigation event. Instead of making a network request, it uses the browser's History API to change the URL in the address bar without triggering a page reload. The router then looks at the new URL path (e.g., /dashboard) and, based on predefined rules, renders the corresponding component onto the page, replacing the previous one.

When to use it

Use client-side routing for highly interactive applications where a native-app-like feel is crucial. This includes dashboards, social media feeds, and complex forms where users frequently navigate between different views. It's the standard for modern frameworks like React (with React Router), Vue (with Vue Router), and Angular.

When not to use it

Client-side routing is overkill for content-heavy, static sites like blogs or marketing pages. For these, traditional server-side routing is simpler and often more SEO-friendly out of the box, as the server sends fully-rendered HTML. Using a client-side SPA for a simple blog can lead to slower initial loads and unnecessary complexity.

One canonical example

A user is on yourapp.com/feed and clicks a link to their profile. The router prevents a full page load, immediately updates the URL to yourapp.com/profile, and swaps the Feed component with the Profile component. The transition is instant because the code was already downloaded. The only network activity might be a fetch request for the specific profile data, not the whole page.

Interview question

What is the fundamental way client-side routing avoids a full page reload when a user navigates to a new view?

  • a.It intercepts the browser's navigation event and dynamically renders a different component already present in the browser.Correct
  • b.It fetches only the necessary data for the new view from the server, not new HTML.
  • c.It uses server-side logic to send only the updated portions of the page.
  • d.It pre-loads all potential page content into the browser's cache for immediate display.
Why?

Client-side routing prevents full page reloads by intercepting navigation events, updating the URL with the History API, and then dynamically rendering a different UI component that was already loaded within the single HTML page. Option B describes a common data fetching pattern in SPAs, but the routing mechanism itself prevents the full page reload by managing the UI components locally, not just by fetching data.

Just read this? Test yourself on what you have been reading.

Read the original → en.wikipedia.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on spa — each one lists the topics its interview covers.

See open roles