From 44c63a963f05ede229d8658a45b2388e244ce00b Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 24 Jul 2019 16:33:17 +0200 Subject: [PATCH] feat: warn the user for invalid uses of v-slot with Link --- src/components/link.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/link.js b/src/components/link.js index f6b39ae8d..f246561fd 100644 --- a/src/components/link.js +++ b/src/components/link.js @@ -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 = [String, Object] @@ -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') {