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

153
Views
Is there a way I can nest a button inside of a router link, and when it's clicked to only trigger the button instead of both?

To clarify, I have this router link inside a navbar, which has a button on top of it that changes the route.

Here's code for context:

<router-link v-if="foo" :to="/">
...
  <button @click="redirect"> GO </button>
...

The method for redirection:

redirect() { this.$router.push('/myroute').catch(() => {})

I tried using z index on both elements, but every time I click on the GO button it first goes to the '/myroute' and then goes back to '/'

Is there a way I can work around this?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You could call event.stopPropagation() to prevent this event being propagated in the bubbling phase. So the event will stop only on the button element.

redirect(e) {
    e.stopPropagation();
    this.$router.push('/myroute').catch(() => {});
}
about 4 years ago · Juan Pablo Isaza Report

0

You can use the stop modifier to @click.

<router-link v-if="foo" :to="/">
...
  <button @click.stop="redirect"> GO </button>
...

This is the vue equivalent of stopPropagation.

The z-index is more about the display of the button. Events propagate such that when you click on an inner DOM element, you're also clicking on everything that's at the (x,y) including the containing node. If there's nothing else listening to that event (which is usually the case) then the click does what you want.

Another alternative is to make the button and the router-link siblings, and use an outer <div></div> with some flex styling to place them where you want.

about 4 years ago · Juan Pablo Isaza Report
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!