How to get current URL in Vue JS?

June 24, 2018 | Category : Vue.js

Are you wanted to get current url in your Vue js app ? If yes then you are a right place. if you are working with plan vuejs without using vue js route then you can get with window object. but if you are using vue js route then you can also get with route object. so it is a very simple way we can get current url.

I give you bellow both example, just see it and ut it those you require...

index.html

<!DOCTYPE html>

<html>

<head>

<title>How to get current URL in Vue JS?- HDTuto.com</title>

<script src="https://cdn.jsdelivr.net/npm/vue"></script>

</head>

<body>


<div id="app">

{{ message }}

</div>


<script type="text/javascript">

var app = new Vue({

el: '#app',

data: {

message: 'Hello Vue!'

},

created: function(){

var currentUrl = window.location.pathname;

console.log(currentUrl);

}

})

</script>


</body>

</html>

If you use $route

this.$route.query.page

I hope you found your solution...