Simple question. I have a router link inside a clickable table row. when I click the router link it triggers the @click
event instead of triggering the router-link
.
How can I fix this?
<tr v-for="(blabla, index) in data" @click="goToIssue(blabla.id)">
<td>{{ blabla.id }}</td>
<td>{{ blabla.username }}</td>
<td>{{ blabla.name }}</td>
<td>
<router-link
:to="'/project' + blabla.project.id"
>
Details
</router-link>
</td>
</tr>
To stop the
click
-event from bubbling to the parent, use a custom<router-link>
that uses thestop
event modifier on the underlying link's@click
:Apply the
custom
prop on the<router-link>
.In the
<router-link>
's default slot, add an<a>
with itshref
bound to the slot'shref
prop.Also add a
click
-event handler that calls the slot'snavigate
prop (a function that navigates to<router-link>
'sto
prop). Also apply the.stop
event modifier to theclick
-event listener to stop the event from propagating to the parent elements.demo