WICG / navigation-api

The new navigation API provides a new interface for navigations and session history, with a focus on single-page application navigations.
https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigation-api
487 stars 26 forks source link

Extend NavigationInterceptOptions - optional url field #249

Closed uasan closed 2 years ago

uasan commented 2 years ago

There are many cases (trailing slashes, the most common case) where it is necessary to change the url in the navigation event handler method without canceling the current event and not create new event.

For example, we have canonical urls, if the user go to a non-canonical alias, we need to make the transition, but change this url to canonical, without canceling the current event, so that the caller does not receive a cancellation exception.

I propose extends NavigationInterceptOptions add optional property url - correct string value within the current location.origin.

navigation.addEventListener('navigate', e => {
  //...
  e.intercept({
    url: isNonCanonical(e.destination.url) ? getCanonical(e.destination.url) : undefined,
    async handler() {
      // ....
    }
  });
});

What do you think?

tbondwilkinson commented 2 years ago

Is this the same request as a client side redirect? #124

uasan commented 2 years ago

Thanks, I didn’t read it. Yes, these are solutions to the same problems. I briefly suggested a simple solution here using a real example

domenic commented 2 years ago

Yeah, let's roll this into #124. Thanks for showing up to let us know that feature is important to you!