From 2ba5ba7effbd19681dac9a55f74953eb12dbc82b Mon Sep 17 00:00:00 2001 From: Vinicius Reis Date: Wed, 14 Dec 2016 00:17:03 -0200 Subject: [PATCH 1/2] add options. custumize vuex module name --- index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 8680fb4..38f0a5f 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, to) { - store.state.route = Object.freeze({ + store.state[moduleName] = Object.freeze({ name: to.name, path: to.path, hash: to.hash, @@ -20,7 +22,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 From 72ddcb6e55f81603b3664f0e7813764ce45f609c Mon Sep 17 00:00:00 2001 From: Vinicius Reis Date: Wed, 14 Dec 2016 00:21:34 -0200 Subject: [PATCH 2/2] add doc --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) 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: