skip to content

Navigation, History & Restoration

Intercepting link clicks, navigating programmatically, treating back and forward as a cancelable pending transition, then restoring scroll, focus and title. Interviewers press hard on the back button.

on this pageshow

questions

6

How should a router stop a user leaving a form with unsaved changes, and what can it not stop?

level: seniorimportance: must knowfreq 56%

basics

~20 s

Register a blocker while the form is dirty: the router consults it before committing any navigation it controls, holding the transition open until the user answers. A real document unload can only be asked about, never blocked.

open as a page

A client-side router redirects by pushing a new history entry. Why does pressing Back bounce the user forward again?

level: middleimportance: should knowfreq 54%

basics

~20 s

Pushing leaves the pre-redirect address on the stack, so Back lands on it, the same condition redirects again, and the user is pushed forward. A navigation that corrects the current location must replace that entry, not add one.

open as a page

Why do routers treat a navigation as a cancelable pending transition instead of swapping the screen immediately?

level: seniorimportance: should knowfreq 48%

basics

~20 s

Because the next screen is rarely ready when the address changes. A pending transition keeps the current screen visible and interactive, and can be abandoned when a second navigation supersedes it, so a slow first one cannot commit late.

open as a page

After a client-side router commits a navigation, how does it decide the new screen's scroll position, focus and title?

level: seniorimportance: should knowfreq 46%

basics

~20 s

A client-side commit resets nothing by itself, so the router needs a policy: top for a new destination, the saved offset for that history entry on a traversal, unchanged for a refinement, focus and title per route.

open as a page