Skip to content

Commit

Permalink
adjust <router-link> click listener target when wrapping <a>
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 21, 2016
1 parent e0de642 commit e5f0964
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/components/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,30 @@ export default {
? isSameRoute(current, compareTarget)
: isIncludedRoute(current, compareTarget)

const data: any = {
class: classes,
on: {
click: (e) => {
e.preventDefault()
if (this.replace) {
router.replace(to)
} else {
router.push(to)
}
const on = {
click: (e) => {
e.preventDefault()

This comment has been minimized.

Copy link
@lifeforfun

lifeforfun Sep 27, 2016

Should you add e.stopPropagation() to prevent parent node click listener ?
I have the code as below:

  <router-link tag="li" :to="item.path" data-toggle="dropdown-menu" data-trigger="hover">
      <a>parent menu</a>
      <ul v-if="item.children">
          <router-link v-for="child of item.children"  tag="li" :to="child.path">
               <a>child menu</a>
          </router-link>
      </ul>
  </router-link>

When i click a child menu , it first trigger the child menu and then trigger the parent menu, cause the route become parent menu.

if (this.replace) {
router.replace(to)
} else {
router.push(to)
}
}
}

const data: any = {
class: classes
}

if (this.tag === 'a') {
data.on = on
data.attrs = { href }
} else {
// find the first <a> child and apply href
// find the first <a> child and apply listener and href
const a = findAnchor(this.$slots.default)
if (a) {
const aData = a.data || (a.data = {})
aData.on = on
const aAttrs = aData.attrs || (aData.attrs = {})
aAttrs.href = href
}
Expand Down

0 comments on commit e5f0964

Please sign in to comment.