Sometimes, we want to get the current route path of lazy-loaded modules on page load with Vue.js and Vue Router.
In this article, we’ll look at how to get the current route path of lazy-loaded modules on page load with Vue.js and Vue Router.
How to get the current route path of lazy-loaded modules on page load with Vue.js and Vue Router?
To get the current route path of lazy-loaded modules on page load with Vue.js and Vue Router, we can use the this.$route.path property.
For instance, we write
<script>
//...
export default {
  //...
  methods: {
    get() {
      console.log(this.$route.path);
    },
  },
  //...
};
</script>
to log the value of the current route’s URL path by logging the this.$route.path property in the get method.
Conclusion
To get the current route path of lazy-loaded modules on page load with Vue.js and Vue Router, we can use the this.$route.path property.