vuetify icon indicating copy to clipboard operation
vuetify copied to clipboard

[Feature Request] Support nuxt prop for Vuetify 3 on Routable components

Open oemer-aran opened this issue 2 years ago • 8 comments

Problem to solve

In Vuetify2 adding the nuxt to a routable component (e.g. v-btn or v-card) produced a nuxt-link if to prop or href prop was passed. In Vuetify 3 the nuxt prop does no longer exist.

Proposed solution

Without nuxt prop: <v-btn href="https://vuetifyjs.com"/> => <a href="https://vuetifyjs.com"/> <v-btn to="/vuetify"/> => <router-link to="/vuetify"/> <v-btn /> => <button /> (No href or to)

With nuxt prop: <v-btn nuxt href="https://vuetifyjs.com"/> => <nuxt-link href="https://vuetifyjs.com"/> <v-btn nuxt to="/vuetify"/> => <nuxt-link to="/vuetify"/> <v-btn nuxt /> => <button /> (No href or to)

NOTE: nuxt-link can now handle internal (to) and external (href) links: https://nuxt.com/docs/api/components/nuxt-link

oemer-aran avatar May 29 '23 19:05 oemer-aran

@johnleider plans for this?

lioneaglesolutions avatar May 30 '23 19:05 lioneaglesolutions

Was hoping for a community contribution since none of the team uses nuxt.

johnleider avatar May 30 '23 21:05 johnleider

Nuxt would have to expose a vue-router compatible useLink function on the component.

KaelWD avatar May 31 '23 05:05 KaelWD

Hi 👋 @KaelWD, I have raised an issue in nuxt repo: nuxt/nuxt#22169. Will vuetify team implement this feature once useLink function is added to NuxtLink? If not, how to implement this feature?

so1ve avatar Aug 06 '23 11:08 so1ve

I noticed the button and others components use render function like way to render, we can use custom tag property to implement this feature, but will get a typescript error because the tag property doesn't accept vue component type.

https://github.com/vuetifyjs/vuetify/blob/a997c424f8660894555804bfcb88761cfead9238/packages/vuetify/src/components/VBtn/VBtn.tsx#L157C1-L168C54

The code will like this:

<v-btn :tag="RouterLink" to="/">Link</v-btn>

I didn't find way to directly use the NuxtLink component in code, so I made a wrapper of NuxtLink. That is the RouterLink referenced in previous code.

<template>
  <nuxt-link v-bind="props" />
</template>

<script setup lang="ts">
// Add other properties if you want
const props = defineProps<{ to: string; target: string }>();
</script>

I tested this solution, looks everything works fine. Except the warning.

image

LittleSheep2Code avatar Mar 16 '24 16:03 LittleSheep2Code

@KaelWD This has been done on Nuxt side: https://github.com/nuxt/nuxt/issues/22169, do you know when this might be expedited?

AnttechDev avatar May 10 '24 21:05 AnttechDev

https://github.com/vuetifyjs/vuetify/pull/19514#issuecomment-2065784246

KaelWD avatar May 11 '24 05:05 KaelWD

#19514 (comment)

@KaelWD, I agree with you. If it doesn't bring prefetching, it has almost no advantage. Maybe we should hope that prefetch will be added to useLink later.

alihardan avatar May 11 '24 08:05 alihardan

Was hoping for a community contribution since none of the team uses nuxt.

@johnleider if no one is on I can tackle this one

gsouf avatar Sep 27 '24 00:09 gsouf