onlinecode

Getting the current route path in Vue

Getting the current route path in Vue

In this post we will give you information about Getting the current route path in Vue. Hear we will give you detail about Getting the current route path in VueAnd how to use it also give you demo for it if it is necessary.

we will learn about how to get the current route path in Vue router.

We can use this.$router.currentRoute.path property in a vue router component to get the current path.

Example:

Post.vue
<template>  <div>    <h1>Post page</h1>  </div></template><script>export default {  created() {    console.log(this.$router.currentRoute.path); // path is /post  }};</script>

Inside the vue template, you access it like this.

<template>  <div>    <h1>current path is {{$router.currentRoute.path}}</h1>  </div></template>

Similarly, you can also use this.$route.path property.

Post.vue
<template>  <div>    <h1>Post page</h1>    <p>current path is {{$route.path}}</p>  </div></template><script>export default {  created() {    console.log(this.$route.path); // path is /post  }};</script>

Hope this code and post will helped you for implement Getting the current route path in Vue. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Exit mobile version