You can use vue-router-sync
library to sync current $route object in vuex store's state.
The usage is quite straight forward with two steps
- Installation:
npm install vuex-router-sync
- Sync router and store:
import { sync } from 'vuex-router-sync'
import store from './vuex/store' // vuex store instance
import router from './router' // vue-router instance
const unsync = sync(store, router) // Returns an unsync callback function
unsync() // Unsyncs store from router