Skip to content

Commit

Permalink
feat: warn the user for invalid uses of v-slot with Link
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jul 24, 2019
1 parent d6ba930 commit 44c63a9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { createRoute, isSameRoute, isIncludedRoute } from '../util/route'
import { extend } from '../util/misc'
import { normalizeLocation } from '../util/location'
import { warn } from '../util/warn'

// work around weird flow bug
const toTypes: Array<Function> = [String, Object]
Expand Down Expand Up @@ -97,8 +98,19 @@ export default {
})

if (scopedSlot) {
if (scopedSlot.length > 1 || !scopedSlot.length) throw new Error('no')
return scopedSlot[0]
if (scopedSlot.length === 1) {
return scopedSlot[0]
} else if (scopedSlot.length > 1 || !scopedSlot.length) {
if (process.env.NODE_ENV !== 'production') {
warn(
false,
`RouterLink with to="${
this.props.to
}" is trying to use a scoped slot but it didn't provide exactly one child.`
)
}
return scopedSlot.length === 0 ? h() : h('span', {}, scopedSlot)
}
}

if (this.tag === 'a') {
Expand Down

0 comments on commit 44c63a9

Please sign in to comment.