Skip to content

Commit

Permalink
feat(link): deprecate v-slot without custom prop
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jan 5, 2021
1 parent fb9bb60 commit ceeda4c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/basic/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const vueInstance = new Vue({
<li><router-link :to="encodeURI('/é')">/é</router-link></li>
<li><router-link :to="encodeURI('/é?t=%ñ')">/é?t=%ñ</router-link></li>
<li><router-link :to="encodeURI('/é#%ñ')">/é#%25ñ</router-link></li>
<router-link to="/foo" v-slot="props">
<router-link to="/foo" v-slot="props" custom>
<li :class="[props.isActive && 'active', props.isExactActive && 'exact-active']">
<a :href="props.href" @click="props.navigate">{{ props.route.path }} (with v-slot).</a>
</li>
Expand Down
9 changes: 8 additions & 1 deletion src/components/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const eventTypes: Array<Function> = [String, Array]

const noop = () => {}

let warnedCustomSlot

export default {
name: 'RouterLink',
props: {
Expand All @@ -22,6 +24,7 @@ export default {
type: String,
default: 'a'
},
custom: Boolean,
exact: Boolean,
append: Boolean,
replace: Boolean,
Expand Down Expand Up @@ -106,13 +109,17 @@ export default {
})

if (scopedSlot) {
if (process.env.NODE_ENV !== 'production' && !this.custom) {
!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')
warnedCustomSlot = true
}
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="${
`<router-link> with to="${
this.to
}" is trying to use a scoped slot but it didn't provide exactly one child. Wrapping the content with a span element.`
)
Expand Down

0 comments on commit ceeda4c

Please sign in to comment.