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
485 stars 30 forks source link

Replace and/or info on anchor navigations? #173

Closed frehner closed 2 years ago

frehner commented 2 years ago

(Sorry if this was discussed before; I did some searches and couldn't find anything.)

One of the cool advantages of App History is that you can use standard anchor tags for navigations, and there's no need to call the API directly. Under the hood, it's essentially like calling appHistory.navigate() when you click an anchor tag, right?

But the navigate() method takes in an additional prop; an object which has things like state, info, and replace. If I need to add that info to my navigation, do I need to revert back to event.preventDefault()-ing the anchor click event and then calling appHistory.navigate() myself?

Or can there be other ways of doing that? (Or do they already exist?)

As an example, could there be additional HTML attributes added to the anchor tag that automatically signals whether it should be a replace navigation? <a href="/url" app-history-replace="true"> as one extremely verbose example of what it could look like. A downside of this would probably be that you couldn't have complex objects for info or state (unless you stringify them), but maybe this is still better than the alternative of not having anything at all?

Anyway, hopefully my questions make sense. 🙂 Let me know if I need to clarify anything.

domenic commented 2 years ago

This is https://github.com/WICG/app-history/issues/101 :)

frehner commented 2 years ago

Ah dang totally missed that. Sorry!