Skip to content

Commit 44c63a9

Browse files
committedJul 24, 2019
feat: warn the user for invalid uses of v-slot with Link
1 parent d6ba930 commit 44c63a9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed
 

‎src/components/link.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { createRoute, isSameRoute, isIncludedRoute } from '../util/route'
44
import { extend } from '../util/misc'
55
import { normalizeLocation } from '../util/location'
6+
import { warn } from '../util/warn'
67

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

99100
if (scopedSlot) {
100-
if (scopedSlot.length > 1 || !scopedSlot.length) throw new Error('no')
101-
return scopedSlot[0]
101+
if (scopedSlot.length === 1) {
102+
return scopedSlot[0]
103+
} else if (scopedSlot.length > 1 || !scopedSlot.length) {
104+
if (process.env.NODE_ENV !== 'production') {
105+
warn(
106+
false,
107+
`RouterLink with to="${
108+
this.props.to
109+
}" is trying to use a scoped slot but it didn't provide exactly one child.`
110+
)
111+
}
112+
return scopedSlot.length === 0 ? h() : h('span', {}, scopedSlot)
113+
}
102114
}
103115

104116
if (this.tag === 'a') {

0 commit comments

Comments
 (0)