Vue.js router-link issue
See original GitHub issueIt seems like <router-link />
(vue-router-next) doesn’t work the same inside a <MenuItem />
as it does outside of it.
Here’s a little demo: https://codesandbox.io/s/headlessuivue-menu-example-forked-xiitu
When navigating between Home & About pages from the Menu, the page refreshes completely. When navigating with the top links it doesn’t, as it should be.
Any idea what’s happening?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
vue-router : router-link not working - Stack Overflow
In my case router-link is not working because i have sidebar outside of <div id="app"></div>. So the moral of the story is we...
Read more >Router not working on 4.0.14 -> Use the vue-devtools stable to ...
I am having the same problem with same vue-router version 4.0.14 but without any errors on dev tools console. There is nothing logged,...
Read more >Router-link to is not working as a link, it just showing as a ...
Router-link to is not working as a link, it just showing as a simple text ... Vue = require('vue'); import VueRouter from 'vue-router' ......
Read more ><router-link> is not clickable - Laracasts
<router-link> is not clickable. Hi guys,. I am building laravel vue js app ... but i am facing a problem with the router,...
Read more >How to Use Vue Router: A Complete Tutorial - Vue School Blog
However unlike an anchor link ( <a href=""> tag) the <router-link> will not reload the whole page. Remember Vue is a single-page application....
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 Free
Top 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
I fixed a sort of related issue earlier (#249), so that we can get access to the underlying DOM node, even when using a custom component. You can already try it using
npm install @headlessui/vue@dev
oryarn add @headlessui/vue@dev
.But it seems like the router-link doesn’t forward all the props correctly (aka the onClick prop). The fix @ryzr provided can help you, however make sure to put the
@click
on theMenuItem
(so that we can merge the clicks) instead of on thea
tag.Here is a codesandbox: https://codesandbox.io/s/headlessuivue-menu-example-forked-31t3b?file=/src/components/Menu.vue
Hey, I was able to get around this by using router-link slots:
It doesn’t seem to work if RouterLink is a child to MenuItem. This might be because RouterLink does not have
emits: ['click']
? I’m not fully across the Vue 3 event system, so I could be wrong here.