0👍
I believe YES, you can do it. But you need to know a few things.
If you have a named route, it is simpler. Just do the following:
// pass params to named route
this.$router.push ({name: 'user', params: {userId: '123'}})
// get params from named route in other component
console.log(this.$router.params)
However if you don’t have a named route created you can do something less elegant, but it will work…
It would be interesting to take a look at the vue documentation at this link https://router.vuejs.org/guide/essentials/navigation.html. Here is a lot of information explaining this better.
But let’s go to the example, supposing that you use router.push, and that you understand that it is possible to execute a function after the replace occours, say that you could do something like this:
this.$router.push(
{
path: 'YOUR/PATH',
},
// onComplete Function
(myValue) => {
// save the value in localStorage
localStorage.setItem('VALUE', JSON.stringify(myValue))
// to retrieve the value you can get with
console.log(JSON.parse(localStorage.getItem('VALUE')))
// save the value in store with vuex
this.$store.dispatch('doSomethingFromAction', myValue)
this.$store.commit('doSomethingFromMutation', myValue)
// to retrieve the value you can get with
console.log(this.$store.state.myValue)
})
If you don’t know vuex, take a look in the docs: https://vuex.vuejs.org/
Source:stackexchange.com