-
Notifications
You must be signed in to change notification settings - Fork 28
Description
The explainer details why window.history
is an unfortunate API. Given a web developer starting from scratch on a new application, in the glorious future where app history ships everywhere, it seems like it'd be nice if such a web developer could ignore window.history
entirely.
With the current design, this is mostly possible, with one exception: the navigation API's control over scroll restoration is not complete compared to history.scrollRestoration
. In particular it does not control cross-document scroll restoration.
Should it have that ability? What would that look like?
Other issues to note in the comparison
-
The navigation API, by design, doesn't have any insight into other-frame history entries. If an application needs such capabilities, it would need to coordinate with those frames, either by using
iframeEl.contentWindow.navigation
for same-origin-domain frames, orpostMessage()
ing to cross-origin-domain frames. -
The navigation API takes on a very different model for single-page app navs, as explained in this section. In particular it has no counterpart to
history.pushState()
orreplaceState()
which just update the current document's URL; instead you need to intercept a navigation using thenavigate
event and then usetransitionWhile()
inside the event handler. This is by design, but it's possible there are cases we haven't thought of yet where just updating the current document's URL is a good idea.
A similar question is, should you be able to use navigation
instead of using location
? The combined capabilities of navigation.navigate()
and navigation.currentEntry.url
cover much of Location
. However:
- The convenience getters/setters like
location.hash
orlocation.pathname
require more work to emulate, e.g.(new URL(navigation.currentEntry.url)).hash
, or several lines for the setters. - There is no counterpart to
location.ancestorOrigins
.