Skip to content

REQUEST | useLeaveGuard | Confirm dialog before page leave #4350

@scottix

Description

Clear and concise description of the problem

I was looking for an easy way to setup a leave guard, its common when you make changes to a page and didn't save them. A confirm dialog would normally popup before you close or leave the page. Having an easy way to set this up would be a great addition.

Suggested solution

I created my own use function but essentially you listen to the beforeunload event. This will occur when user closes the page. The other one is using vue-router when using a link to navigate away and hooking into router.beforeEach to prevent navigation.

Alternative

Using the default confirm maybe by default. Customizing the text. Or some sort of callback so the developer can create a function to return true or false on whether to leave or not.

Additional context

You could return a ref that the developer can use to toggle whether he wants the dialog to appear or not. Maybe some options to adjust the confirm message.

Validations

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions