Skip to content

Commit

Permalink
tweak route state setting
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 14, 2016
1 parent 3a6b4ff commit 8f7c970
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@ exports.sync = function (store, router, options) {
state: {},
mutations: {
'router/ROUTE_CHANGED': function (state, transition) {
store.state[moduleName] = Object.freeze({
name: transition.to.name,
path: transition.to.path,
hash: transition.to.hash,
query: transition.to.query,
params: transition.to.params,
fullPath: transition.to.fullPath,
meta: transition.to.meta,
from: transition.from
})
store.state[moduleName] = cloneRoute(transition.to, transition.from)
}
}
})
Expand Down Expand Up @@ -46,3 +37,19 @@ exports.sync = function (store, router, options) {
store.commit('router/ROUTE_CHANGED', { to: to, from: from })
})
}

function cloneRoute (to, from) {
const clone = {
name: to.name,
path: to.path,
hash: to.hash,
query: to.query,
params: to.params,
fullPath: to.fullPath,
meta: to.meta
}
if (from) {
clone.from = cloneRoute(from)
}
return Object.freeze(clone)
}

0 comments on commit 8f7c970

Please sign in to comment.