I have a link like below in a vue component file.
<li v-for="(word,index) in allWord" v-bind:key="index">
<router-link :to="{ name: 'word', params: {id: word.id } }">
{{word}}
</router-link>
</li>
My route settings in index.js file is like below
export default new Router({
mode: 'history',
routes: [
{
path: '/',
component: MainBody
},
{ path: '/word/:id',
name: 'word',
component: Word
}
]
});
I am getting URL like below
http://localhost:8080/word/4
I am trying to catch URL parameter in word.vue is like below
<script>
export default {
watch: {
'$route': 'routeChanged'
},
methods: {
routeChanged () {
console.log(this.$route.params.id);
}
}
}
</script>
The issue is when I click on the <li></li> I am not getting any value in console, I am getting value when I click second time.
Why it is happening ? I would like to get value first time.