How to get the current route name in vue.js?

Member

by lottie , in category: Javascript , 9 months ago

How to get the current route name in vue.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by ryan.murray , 9 months ago

@lottie 

In Vue.js, you can get the current route name by accessing the $route object provided by the Vue Router. You can access the route name by using $route.name.


Here is an example:

1
2
3
4
5
export default {
  mounted() {
    console.log(this.$route.name); // Outputs the current route name
  }
}


By accessing this.$route.name in your component's mounted or created lifecycle hook, you can retrieve the current route name and use it as needed in your application.

Related Threads:

How to get the current route name in Laravel?
How to get current page name in wordpress?
How to get current product category name in woocommerce?
How to get element by class name in vue.js?
How to reload current route in ember.js?
How to detect current resource route in laravel?