Skip to content

Commit ceeda4c

Browse files
committedJan 5, 2021
feat(link): deprecate v-slot without custom prop
1 parent fb9bb60 commit ceeda4c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
 

‎examples/basic/app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const vueInstance = new Vue({
7979
<li><router-link :to="encodeURI('/é')">/é</router-link></li>
8080
<li><router-link :to="encodeURI('/é?t=%ñ')">/é?t=%ñ</router-link></li>
8181
<li><router-link :to="encodeURI('/é#%ñ')">/é#%25ñ</router-link></li>
82-
<router-link to="/foo" v-slot="props">
82+
<router-link to="/foo" v-slot="props" custom>
8383
<li :class="[props.isActive && 'active', props.isExactActive && 'exact-active']">
8484
<a :href="props.href" @click="props.navigate">{{ props.route.path }} (with v-slot).</a>
8585
</li>

‎src/components/link.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const eventTypes: Array<Function> = [String, Array]
1111

1212
const noop = () => {}
1313

14+
let warnedCustomSlot
15+
1416
export default {
1517
name: 'RouterLink',
1618
props: {
@@ -22,6 +24,7 @@ export default {
2224
type: String,
2325
default: 'a'
2426
},
27+
custom: Boolean,
2528
exact: Boolean,
2629
append: Boolean,
2730
replace: Boolean,
@@ -106,13 +109,17 @@ export default {
106109
})
107110

108111
if (scopedSlot) {
112+
if (process.env.NODE_ENV !== 'production' && !this.custom) {
113+
!warnedCustomSlot && warn(false, 'In Vue Router 4, the v-slot API will by default wrap its content with an <a> element. Use the custom prop to remove this warning:\n<router-link v-slot="{ navigate, href }" custom></router-link>\n')
114+
warnedCustomSlot = true
115+
}
109116
if (scopedSlot.length === 1) {
110117
return scopedSlot[0]
111118
} else if (scopedSlot.length > 1 || !scopedSlot.length) {
112119
if (process.env.NODE_ENV !== 'production') {
113120
warn(
114121
false,
115-
`RouterLink with to="${
122+
`<router-link> with to="${
116123
this.to
117124
}" is trying to use a scoped slot but it didn't provide exactly one child. Wrapping the content with a span element.`
118125
)

0 commit comments

Comments
 (0)