Search code examples
javascriptvue.jsroutesvue-componentvue-cli-3

How to hide/unhide the router-link button for a specific component in vuejs


I am using router-link as the button to navigate between different components. Is there any way to hide the component for a particular component.

<router-link :to="{path: prevPage }" tag="button" class="btn btn-primary">

Solution

  • You can get the path of the current route by two ways

    v-if="$route.path != '/'"
    

    or

    v-if="$router.currentRoute.path != '/'"
    

    They both returns a string that equals the path of the current route, always resolved as an absolute path.

    You can check the documentation : https://router.vuejs.org/api/#route-object-properties

    You can check this fiddle: https://jsfiddle.net/Farouk_Mekkaoui/7xvpje08/12/