Skip to content

Async onBeforeRouteLeave composition-api in-component navigation guard #926

@avenmore

Description

@avenmore

What problem does this feature solve?

This would allow code returning a promise to be waited for before cancelling or allowing the route change to happen. The documentation example for this navigation guard (https://next.router.vuejs.org/guide/advanced/composition-api.html#navigation-guards) uses window.confirm() which is not flexible an not likely to suit the application style.

What does the proposed API look like?

Example usage:

import { onBeforeRouteLeave } from 'vue-router';

onBeforeRouteLeave(async () => {
    if (await myDialog.prompt('Save changes')) {
        if (await saveChanges())
            return true;
    }
    return false;
})

Currently (4.0.3) this does not wait.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions