Skip to content

Commit dd9dad2

Browse files
vinicius73yyx990803
authored andcommitted
Custom module name (#37)
* add options. custumize vuex module name * add doc
1 parent 3232eac commit dd9dad2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ sync(store, router) // done.
1919
// bootstrap your app...
2020
```
2121

22+
You can set a custom vuex module name
23+
24+
```js
25+
sync(store, router, { moduleName: 'RouteModule' } )
26+
```
27+
28+
2229
### How does it work?
2330

2431
- It adds a `route` module into the store, which contains the state representing the current route:

index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
exports.sync = function (store, router) {
2-
store.registerModule('route', {
1+
exports.sync = function (store, router, options) {
2+
var moduleName = (options || {}).moduleName || 'route'
3+
4+
store.registerModule(moduleName, {
35
state: {},
46
mutations: {
57
'router/ROUTE_CHANGED': function (state, transition) {
6-
store.state.route = Object.freeze({
8+
store.state[moduleName] = Object.freeze({
79
name: transition.to.name,
810
path: transition.to.path,
911
hash: transition.to.hash,
@@ -22,7 +24,7 @@ exports.sync = function (store, router) {
2224

2325
// sync router on store change
2426
store.watch(
25-
function (state) { return state.route },
27+
function (state) { return state[moduleName] },
2628
function (route) {
2729
if (route.fullPath === currentPath) {
2830
return

0 commit comments

Comments
 (0)