11exports . sync = function ( store , router , options ) {
2- var moduleName = ( options || { } ) . moduleName || 'route'
2+ const moduleName = ( options || { } ) . moduleName || 'route'
33
44 store . registerModule ( moduleName , {
55 namespaced : true ,
66 state : cloneRoute ( router . currentRoute ) ,
77 mutations : {
8- 'ROUTE_CHANGED' : function ( state , transition ) {
8+ 'ROUTE_CHANGED' ( state , transition ) {
99 store . state [ moduleName ] = cloneRoute ( transition . to , transition . from )
1010 }
1111 }
1212 } )
1313
14- var isTimeTraveling = false
15- var currentPath
14+ let isTimeTraveling = false
15+ let currentPath
1616
1717 // sync router on store change
18- var storeUnwatch = store . watch (
19- function ( state ) { return state [ moduleName ] } ,
20- function ( route ) {
21- var fullPath = route . fullPath
18+ const storeUnwatch = store . watch (
19+ state => state [ moduleName ] ,
20+ route => {
21+ const { fullPath } = route
2222 if ( fullPath === currentPath ) {
2323 return
2424 }
@@ -32,13 +32,13 @@ exports.sync = function (store, router, options) {
3232 )
3333
3434 // sync store on router navigation
35- var afterEachUnHook = router . afterEach ( function ( to , from ) {
35+ const afterEachUnHook = router . afterEach ( ( to , from ) => {
3636 if ( isTimeTraveling ) {
3737 isTimeTraveling = false
3838 return
3939 }
4040 currentPath = to . fullPath
41- store . commit ( moduleName + '/ROUTE_CHANGED' , { to : to , from : from } )
41+ store . commit ( moduleName + '/ROUTE_CHANGED' , { to, from } )
4242 } )
4343
4444 return function unsync ( ) {
@@ -58,7 +58,7 @@ exports.sync = function (store, router, options) {
5858}
5959
6060function cloneRoute ( to , from ) {
61- var clone = {
61+ const clone = {
6262 name : to . name ,
6363 path : to . path ,
6464 hash : to . hash ,
0 commit comments