Effortlessly keep vue-router and vuex store in sync.
Note: requires vuex>=0.6.2.
npm install vuex-router-syncimport { sync } from 'vuex-router-sync'
import store from './vuex/store' // vuex store instance
import router from './router' // vue-router instance
sync(store, router) // done.
// bootstrap your app...-
It adds a
routemodule into the store, which contains the state representing the current route:store.state.route.path // current path (string) store.state.route.params // current params (object) store.state.route.query // current query (object)
-
When the router navigates to a new route, the store's state is updated.
-
When the store's
routestate is updated, it notifies the router to navigate to the corresponding path. This enables time-traveling between routes invue-devtools.