Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
Stop router-link until confirm return

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!