File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,13 @@ sync(store, router) // done.
19
19
// bootstrap your app...
20
20
```
21
21
22
+ You can set a custom vuex module name
23
+
24
+ ``` js
25
+ sync (store, router, { moduleName: ' RouteModule' } )
26
+ ```
27
+
28
+
22
29
### How does it work?
23
30
24
31
- It adds a ` route ` module into the store, which contains the state representing the current route:
Original file line number Diff line number Diff line change 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 , {
3
5
state : { } ,
4
6
mutations : {
5
7
'router/ROUTE_CHANGED' : function ( state , transition ) {
6
- store . state . route = Object . freeze ( {
8
+ store . state [ moduleName ] = Object . freeze ( {
7
9
name : transition . to . name ,
8
10
path : transition . to . path ,
9
11
hash : transition . to . hash ,
@@ -22,7 +24,7 @@ exports.sync = function (store, router) {
22
24
23
25
// sync router on store change
24
26
store . watch (
25
- function ( state ) { return state . route } ,
27
+ function ( state ) { return state [ moduleName ] } ,
26
28
function ( route ) {
27
29
if ( route . fullPath === currentPath ) {
28
30
return
You can’t perform that action at this time.
0 commit comments