0

I am new ti Vue and I am trying to get my app to ask the user for confimration before a page refresh (manual) can be done. IS this possible?

I know how to get the confirmation when the user clicks another router link.

I used the example here enter link description here to create this :

import { useRouter, onBeforeRouteLeave } from "vue-router";
    const promptExit = ref(true);
   onBeforeRouteLeave((to, from, next) => {
      if (promptExit.value) {
        const answer = window.confirm('Do you really want to leave? you have unsaved changes!')
  if (answer) {
    from()
  } else {
    from(false)
  }
      } else {
        next();
      }
    });

But is there a way to have the same effect on a hard page refresh on the browser

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
Deji James
  • 367
  • 6
  • 20
  • Vue router is totally unrelated to this. It tracks location changes that are made with history API. – Estus Flask Feb 04 '22 at 18:54
  • Possible duplicate of https://stackoverflow.com/questions/3527041/prevent-any-form-of-page-refresh-using-jquery-javascript?noredirect=1&lq=1 – Estus Flask Feb 04 '22 at 18:59

0 Answers0