Client-Side Routing: No More Full Page Reloads
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.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.