Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a vuejs router-link?

Tags:

I have a single-page app that i've created using vue, and the nav links are all done using router-link tags. There are a couple of items in the nav that my boss wants to have in the nav but disabled so that people can get a glimpse of some features that will be coming soon. However I can't figure out how to completely disable a router-link!

preventDefault does nothing, @click.native.prevent="stopClick()" does nothing (i tried sending it to a function to see if that would prevent the click but it just calls the function and routes anyway despite the prevent), adding a disabled class and setting a css rule of pointer-events: none; does nothing. I'm not sure what else to try, is the only way around this to make the disabled links normal text and not router-links?

like image 552
movac Avatar asked Apr 23 '20 20:04

movac


People also ask

How do I deactivate Vue?

To conditionally disable a button element in Vue. js, you can dynamically bind the disable attribute to an expression that evaluates to boolean true (to disable the button) or false (to enable the button). Please note that :disable is a shorthand syntax for writing v-bind:disable .

How do I turn off Dom link on my react router?

Set the pointer events CSS property to none to disable a Link in React, e.g. <Link style={{pointerEvents: 'none'}}> . When the pointer events property of the link is set to none , the link is disabled.

How do I turn off Vue components?

Vue Button component can be enabled/disabled by giving disabled property. To disable Vue Button component, the disabled property can be set as true .


Video Answer


2 Answers

There is still no native solution today. But there is an open PR for this on the vue-router repo : https://github.com/vuejs/vue-router/pull/2098.

A workaround is to use :

<router-link    :disabled="!whateverActivatesThisLink"    :event="whateverActivatesThisLink ? 'click' : ''"   to="/link" >   /link </router-link> 
like image 144
BTL Avatar answered Sep 30 '22 08:09

BTL


You can use

<router-link    :is="isDisabled ? 'span' : 'router-link'"   to="/link" >   /link </router-link> 
like image 40
Gabriel Berchmann Avatar answered Sep 30 '22 06:09

Gabriel Berchmann