Skip to content
This repository was archived by the owner on Aug 21, 2026. It is now read-only.
This repository was archived by the owner on Aug 21, 2026. It is now read-only.

Behavior of navigate(currentURL, { replace }) #111

Description

@domenic

@jakearchibald, @annevk, @smaug---- and I discussed the behavior of navigation.navigate(appHistory.current.url) today.

The current spec says that this always does a replace navigation, similar to location.href = location.href. This is a bit weird because it means that the replace parameter is ignored, e.g.

// All three of these are equivalent: they all do a replace.
navigation.navigate(navigation.currentEntry.url);
navigation.navigate(navigation.currentEntry.url, { replace: true });
navigation.navigate(navigation.currentEntry.url, { replace: false });

We discussed a few options for what to do:

  1. Do a same-document navigation, either push or replace according to the replace option.

    • Precedent: pushState(null, "") / replaceState(null, "")
    • But, this is not great because in general we want navigate() to be about new-document navigations; to make them same-document, you intercept with the navigate event.
  2. Do a new-document replace navigation, ignoring the replace option

    • Precedent: location.href = location.href, or location.assign(location.href).
    • This is the spec's current behavior.
  3. Do a new-document navigation, either push or replace according to the replace option.

    • A new-document push navigation to the same URL as the current one is only possible today by using redirects, and only in some browsers.
  4. (3), but have the default be a somewhat-magic "replace for same-URL, push for different-URL". I.e.

    navigation.navigate(navigation.currentEntry.url);                      // does a replace
    navigation.navigate(navigation.currentEntry.url, { replace: true });   // does a replace
    navigation.navigate(navigation.currentEntry.url, { replace: false });  // does a push
    
    navigation.navigate(someOtherURL);                                // does a push
    navigation.navigate(someOtherURL, { replace: true });             // does a replace
    navigation.navigate(someOtherURL, { replace: false });            // does a push
  5. Return a rejected promise whenever you pass replace: false and try to navigate to the current URL.

  6. Return a rejected promise whenever you pass anything besides replace: true and try to navigate to the current URL. I.e. you need to be super-explicit.

We were leaning toward (4), although the lack of good precedent is a bit tricky.

Metadata

Metadata

Assignees

No one assigned

    Labels

    changeA proposed change to the API, not foundational, but deeper than the surfacefeedback wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions