0

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">
5
  • Can you elaborate more ? Please. Commented Feb 12, 2019 at 13:37
  • i am using the above <router-link> tab to go back to the previous components in my page. i need it to be hidden in my index page. is that understandable ? Commented Feb 12, 2019 at 13:39
  • You need the path itself to be hidden? Or to not render a component coming from another component? Commented Feb 12, 2019 at 13:45
  • i need that button not to be shown or visible in my page for a particluar component. is that possible ? Commented Feb 12, 2019 at 13:46
  • Gotcha. Is it possible that you include more code? Just to have more context and see if i can help you Commented Feb 12, 2019 at 13:48

2 Answers 2

3

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/

Sign up to request clarification or add additional context in comments.

4 Comments

This hides the button alright, but not displays the button for other components. do you know why ?
You mean that even when the path is different from '/' you still can't see it ?
Yes, it hides the button for all the components
Try to use $route.path without the this or $router.currentRoute.path
1

The answer above helped get me most of the way there but something that worked a little better for me using named routes was:

v-if="$router.currentRoute.name != 'routeNameHere'"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.