I'm building a food-delivery website. I need to tell the user that, when he clicks on the component which redirects him in another page via vuejs2 router-link, his shopping cart will be deleted. At the moment I have this:
<RestaurantBox
v-for="(restaurant, index) in activeRestaurants"
:key="`restaurant${index}`"
:restaurant="restaurant"
@click.native="confirmChange"
/>
with the given function:
confirmChange() {
if (!confirm('Attenzione! Se cambi ristorante perderai quello che hai messo nel carrello.')) {
location.href = '/restaurants/' + this.activeType.slug;
}
}
This kinda works: if I click cancel, the statement in the if does what it should do, but when I click on the component it changes the url via router-link before the confirm(), so it's basically useless. Any ideas?