Before Vue Router 4, I had the following markup:
<router-link
:disabled="!ICanGo(item)"
:tag="!ICanGo(item) ? 'span' : 'a'"
:event="ICanGo(item) ? 'click' : ''"
:to="{ name: 'editUsuario', params: { id: item.id } }"
>{{ item.nome }}</router-link>
With Vue Router 4, I have the following warning now:
[vue-router]
<router-link>'s tag prop is deprecated and has been removed in Vue Router 4. Use the v-slot API to remove this warning: https://next.router.vuejs.org/guide/migration/#removal-of-event-and-tag-props-in-router-link.
How could I change this code to Vue Router 4 recommendations?
Only Vue Router 2 is compatible with Vue 2, so if you're updating Vue, you'll have to update Vue Router as well.
Based on the docs for <router-link>
's v-slot
, the equivalent in Vue Router 4 would be:
<router-link
:to="{ name: 'editUsuario', params: { id: item.id } }"
custom
v-slot="{ href, navigate }"
>
<span v-if="!ICanGo(item)">{{ item.nome }}</span>
<a v-else :href="href" @click="navigate">{{ item.nome }}</a>
</router-link>
There's no need for disabling the element when !ICanGo(item)
because the <span>
itself has no link activation in that case.
demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With