nuxt-link does not resolve inside an as prop
See original GitHub issueEnvironment
- Operating System:
Linux
- Node Version:
v16.14.2
- Nuxt Version:
3.0.0-27501460.04a72f8
- Package Manager:
npm@8.5.5
- Builder:
vite
- User Config:
css
,buildModules
,vite
,build
- Runtime Modules:
-
- Build Modules:
@pinia/nuxt@0.1.8
Reproduction
Code:
<DisclosureButton as="nuxt-link" to="/dashboard" class="block px-4 py-2 text-base font-medium text-gray-500 hover:text-gray-800 hover:bg-gray-100">
Go to dashboard
</DisclosureButton>
HTML:
<nuxt-link disabled="false" to="/dashboard" class="block px-4 py-2 text-base font-medium text-gray-500 hover:text-gray-800 hover:bg-gray-100">
Go to dashboard
</nuxt-link>
Describe the bug
This is not exactly a bug… But if it can be done somehow. The expected result would be the same as if I passed the tag ‘button’.
Example: Code:
<DisclosureButton as="button" to="/dashboard" class="block px-4 py-2 text-base font-medium text-gray-500 hover:text-gray-800 hover:bg-gray-100">
Go to dashboard
</DisclosureButton>
HTML:
<button type="button" to="/dashboard" class="block px-4 py-2 text-base font-medium text-gray-500 hover:text-gray-800 hover:bg-gray-100">
Go to dashboard
</button>
Additional context
No response
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
vue.js - How to interpolate nuxt-link's `to` prop? - Stack Overflow
vue . The problem is that, in my index page, I cannot get <NuxtLink> to go to single post pages. I have a...
Read more >Built-in Components - Nuxt
This prop will be passed to <RouterView> so that your transitions will work correctly inside dynamic pages. There are 2 ways to handle...
Read more >Button | Components - BootstrapVue
You can specify the button's type by setting the prop type to 'button' , 'submit' or 'reset' . The default type is 'button'...
Read more >Language Aware Nuxt.js Routing - Abdelrahman Awad
These types of applications usually do not include the language code in ... then render a nuxt-link component with the newly formed to...
Read more >Passing Props to Route Components | Vue Router
While this is not necessarily a bad thing, we can decouple this behavior with a props option: We can replace. const User =...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m guessing it just can’t resolve the button, since components are more “just in time” imports now. Try this:
I do realise this discussion might not be specifically Nuxt related and is more related to Headless UI with Nuxt. @John-Church that is what I found too. I could use
:as=NuxtLink
successfully to render but it wouldn’t close the DisclosurePanel when activated.So I swapped out each
DisclosureButton
with aNuxtLink
and added a@click
handler to the container that holds those links. The@click
handler simply callsclose()
manually and then every works fine. This is mentioned in HeadlessUI docs for manually closing the panel.It looks something like this:
This works great. Also has the added benefit of being able to track and style the active link in the menu as well. I used a custom component for this something like: