'Vue router props
I would like to pass data with vue router from App.vue to view (Home). Orignial data store in data() App.vuejs and I need to pass this data to view with methods passLanguage().
router
{
path: '/',
name: 'home',
component: HomeView,
props: true
},
app vue
export default {
data () {
return {
cons: 'true'
}
},
methods: {
passLanguage () {
this.$router.push({ name: 'home', params: { data: this.cons } })
}
}
}
Home vue
created () {
this.language = this.$route.params.data
}
Error returned
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/".
Solution 1:[1]
Consider using query params:
app
this.$router.push({ name: 'home', query: { cons: this.cons } })
home
created () {
this.language = this.$route.query.cons
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Romalex |
