question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue.js router-link issue

See original GitHub issue

It 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

3reactions
RobinMalfaitcommented, Feb 19, 2021

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 or yarn 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 the MenuItem (so that we can merge the clicks) instead of on the a tag.

Here is a codesandbox: https://codesandbox.io/s/headlessuivue-menu-example-forked-31t3b?file=/src/components/Menu.vue

1reaction
ryzrcommented, Feb 18, 2021

Hey, I was able to get around this by using router-link slots:

<router-link
  v-slot="{ isActive, href, navigate }"
  custom
  :to="...">
  <MenuItem>
    <a
      :href="href"
      @click="navigate" />
  </MenuItem>
</router-link>

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found