Reputation: 4705
I'm not able to use
this.$route.params
route.params
router.params
how do I get the params of $route in my actions?
Upvotes: 14
Views: 7131
Reputation: 101
You can access the current route through the state or rootState with Vuex.
If the action is in a module, use rootState:
MY_ACTION: ({rootState}) => new Promise((resolve, reject) => {
let params = rootState.route.params
// do stuff
}
If the action is not in a module, use state:
MY_ACTION: ({state}) => new Promise((resolve, reject) => {
let params = state.route.params
// do stuff
}
See https://vuex.vuejs.org/api/#actions for more information on the context object.
Upvotes: 2
Reputation: 448
in your actions.js or store.js
import router from 'path/to/router'
console.log(router.currentRoute.params)
Upvotes: 20