Skip to content

Should this API be able to completely replace window.history? What about window.location? #67

@domenic

Description

@domenic

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, or postMessage()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() or replaceState() which just update the current document's URL; instead you need to intercept a navigation using the navigate event and then use transitionWhile() 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 or location.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    additionA proposed addition which could be added later without impacting the rest of the API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions