9951 explained code solutions for 126 technologies


vue.jsHow can I use Vue.js to get the current URL?


Using Vue.js to get the current URL is easy. You can use the $route object from the vue-router plugin. The $route.path property will give you the current URL.

Example code

console.log(this.$route.path);

Output example

/current/url

The code above will output the current URL. Here is a breakdown of the code:

  • console.log: prints the given parameter to the console
  • this.$route: the $route object from the vue-router plugin
  • $route.path: the property of the $route object that contains the current URL

For more information, you can check out the Vue.js documentation and the vue-router documentation.

Edit this code on GitHub