I want to get the name of the current route of vue-router, i have a component menu with navigation to another componentes, so i want to dispaly the name of the current route. I have this:
created(){ this.currentRoute; //this.nombreRuta = this.$route.name; }, computed:{ currentRoute:{ get(){ this.nombreRuta = this.$route.name; } } }
But the label of the name of the route does not change, the label only show the name of the first loaded route. Thank You
EDIT:
Image to show what i want
Router-view It's basically the view where the components are rendered. It's like the main div that contains all the components, and it returns the component that match the current route.
router-link This allows Vue Router to change the URL without reloading the page, handle URL generation as well as its encoding.
Sometimes, you might want to attach arbitrary information to routes like transition names, who can access the route, etc. This can be achieved through the meta property which accepts an object of properties and can be accessed on the route location and navigation guards.
You are using computed
incorrectly. You should return the property in the function. See the docs for more information.
Here is your adapted example:
computed: { currentRouteName() { return this.$route.name; } }
You can then use it like this:
<div>{{ currentRouteName }}</div>
You can also use it directly in the template without using a computed property, like this:
<div>{{ $route.name }}</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With