-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Prevent accidental leave when the scan is not completed
- Loading branch information
1 parent
bb8b54c
commit c0e7f5d
Showing
2 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function useUnsavedChange(callback: () => string | null | undefined | false, confirm = window.confirm.bind(window)) { | ||
onBeforeRouteLeave((to, from, next) => { | ||
let answer = true | ||
const message = callback() | ||
if (message) { | ||
answer = confirm(message) | ||
} | ||
next(answer) | ||
}) | ||
useEventListener(window, 'beforeunload', (event) => { | ||
if (callback()) { | ||
event.preventDefault() | ||
} | ||
}) | ||
} |