I would like to pass router params into Vuex actions, without having to fetch them for every single action in a large form like so:
edit_sport_type({ rootState,
To get params from vuex
store action, import your vue-router
's instance, then access params of the router instance from your vuex
store via the router.currentRoute object.
Sample implementation below:
router at src/router/index.js
:
import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
Vue.use(VueRouter)
const router = new VueRouter({
mode: 'history',
routes
})
export default router
import the router at vuex store:
import router from '@/router'
then access params at vuex action function, in this case "id", like below:
router.currentRoute.params.id