Vue Js Get Url’s Current Path and Filename: In Vue.js, the current path and filename of a URL can be obtained by using the `window.location.pathname` property, which returns a string containing the path of the currently active route. Here in this tutorial, we will learn how to get the current path and filename by using native Javascript and Vue.js.
Vue.js get Current path and filename Syntax
this.currentPath ='Current Path: '+ window.location.pathname;
How to Get path and filename of the current page in Vue.js?
In order to get the path and filename of the current page in Vue.js, you can use the window.location.pathname object property, which contains information about the current URL
Vue Js Get path and filename from Url | Example
<div id="app">
<button @click="myFunction">Get Url Path</button>
<p>{{currentPath}}</p>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data()
{
return{
currentPath:'',
}
},
methods:{
myFunction(){
this.currentPath ='Current Path: '+ window.location.pathname;
},
}
}).mount('#app')
</script>