这是indexloc提供的服务,不要输入任何密码
Skip to content

Cancelling UI initiated navigations (back/forward) #32

@posva

Description

@posva

Hello, looking at the part regarding navigation cancellation (https://github.com/WICG/app-history#navigation-monitoring-and-interception) and later on, the comparison with navigation guards makes me wonder why can't UI based navigations (or history.back()) be cancelled as well with event.preventDefault() for same document and origin navigations? If they can't be cancelled navigation guards cannot be implemented like proposed since they also run when the user navigates backwards and forwards.
Currently, on Vue Router 4, I restore the history entry (when possible): https://github.com/vuejs/router/blob/main/packages/router/src/router.ts#L1039-L1042 when a ui initiated navigation is cancelled.

It would be even nicer if the URL stays the same until the navigation is confirmed, no matter what initiated it, making it consistent when doing history.back() (or clicking the ui button) or clicking on a link of the application. In applications, users show modals or confirmations messages when before navigating away from a page (e.g. to not lose unsaved changes) and the URL changing is often confusing

All of the above is for same origin and document navigations, which is the context of an SPA.

Metadata

Metadata

Assignees

No one assigned

    Labels

    foundationalFoundational open questions whose resolution may change the model dramatically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions