-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't use is="NuxtLink" with component #13659
Comments
First you can use If you still need to use it in const component = computed(() => {
if (props.to || props.href) return defineNuxtLink({})
return 'button'
}) |
Or, to reuse the existing NuxtLink component: const component = computed(() => {
if (props.to || props.href) return resolveComponent('NuxtLink')
return 'button'
}) Example: https://stackblitz.com/edit/github-vwzpk9?file=app.vue. The reason this is required is that if you don't use NuxtLink it won't be included in your bundle. So we need more than just a string to tell us. If you want it globally registered then you can create your own NuxtLink component with |
Does I tried it in a *.vue file, it returns the actual component |
There's kinda strange behavior when I try to I have a nuxt page where I use a link component:
The components looks like
|
@Dodje It's because NuxtLink isn't globally registered - it's auto-imported. Within a Nuxt project we detect You can probably resolve this in your case by adding your ui library to |
@danielroe thanks for a quick response |
I'll happily look at a reproduction. |
Sometimes life is like a joke, I've created a reproduction repo and... it works just fine :) |
Excellent. 👌 |
@danielroe
|
For those wondering, the correct import is |
I'm having issues with this when generating a NuxtLink using a dynamic component in an external library. I'm trying to support both Vue and Nuxt projects, so I have a component that detects the environment and renders the correct component (see below).
The works for Vue projects but on Nuxt projects it is unable to resolve the NuxtLink component. Is there something I'm missing or is this just not possible with Nuxt? I should also add that this library is written using just Vue, not Nuxt, due to some other restrictions. ------EDIT -------- After spinning my wheels on this for a few hours I fixed the issue within 2 minutes of posting this, typical. It seems like the Vue instance isn't actually aware of the NuxtLink when it renders my component, I'm guessing has something to do with Nuxt's auto-importing. So, as part of my library import I added this to my plugin definition:
Can someone confirm if this is the right way to resolve this issue and maybe give a bit of clarification as to why it works? |
Yes, that's a very reasonable solution. The only reason we don't register NuxtLink globally as if you don't use it we can tree-shake it out of your build. |
This doesnt seem to work, getting this all the time:
|
@deflexor it will work if you use a script setup block, where the import is automatically exposed. Otherwise you need to pass it explicitly to the template. |
Environment
Darwin
v14.18.2
3.0.0-27468803.23e7afb
[email protected]
vite
css
,build
-
-
Reproduction
<component is="NuxtLink" to="/">Example</component>
Generate this html:
<nuxtlink to="/">Example</nuxtlink>
Expected html:
<a aria-current="page" href="/" class="router-link-active router-link-exact-active">Example</a>
Describe the bug
Usage of
<component is="NuxtLink" to="/">
doesn't generate a link, I can't use<component :is="to ? 'NuxtLink' : href ? 'a' : 'button'"
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: