JavaScript Interview Question #172
What is client-side routing?
Performance, Browser APIs, Rendering & Modern Web Architecture Senior Advanced
Quick Interview Answer
Client-side routing maps URL paths to application views without requiring a complete document reload for every navigation. It is common in single-page applications.
Detailed Explanation
Client-side routing maps URL paths to application views without requiring a complete document reload for every navigation. It is common in single-page applications.
A router usually coordinates the History API, link handling, data loading, rendering, and back/forward navigation. Production systems also need server fallback configuration and should preserve accessibility, meaningful URLs, and appropriate loading/error states.
Code Example
function navigate(path) {
history.pushState({}, "", path);
renderRoute(path);
}
window.addEventListener("popstate", () => {
renderRoute(window.location.pathname);
});