diff --git a/README.md b/README.md index f9a1006..905907e 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,13 @@ sync(store, router) // done. // bootstrap your app... ``` +You can set a custom vuex module name + +```js +sync(store, router, { moduleName: 'RouteModule' } ) +``` + + ### How does it work? - It adds a `route` module into the store, which contains the state representing the current route: diff --git a/index.js b/index.js index 559a51f..0a7382a 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,11 @@ -exports.sync = function (store, router) { - store.registerModule('route', { +exports.sync = function (store, router, options) { + var moduleName = (options || {}).moduleName || 'route' + + store.registerModule(moduleName, { state: {}, mutations: { 'router/ROUTE_CHANGED': function (state, transition) { - store.state.route = Object.freeze({ + store.state[moduleName] = Object.freeze({ name: transition.to.name, path: transition.to.path, hash: transition.to.hash, @@ -22,7 +24,7 @@ exports.sync = function (store, router) { // sync router on store change store.watch( - function (state) { return state.route }, + function (state) { return state[moduleName] }, function (route) { if (route.fullPath === currentPath) { return