Skip to content

Commit

Permalink
[29] Store 'from' in state.route (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
predhme authored and yyx990803 committed Dec 14, 2016
1 parent 7a269fe commit 3232eac
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ exports.sync = function (store, router) {
store.registerModule('route', {
state: {},
mutations: {
'router/ROUTE_CHANGED': function (state, to) {
'router/ROUTE_CHANGED': function (state, transition) {
store.state.route = Object.freeze({
name: to.name,
path: to.path,
hash: to.hash,
query: to.query,
params: to.params,
fullPath: to.fullPath,
meta: to.meta
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
})
}
}
Expand All @@ -34,12 +35,12 @@ exports.sync = function (store, router) {
)

// sync store on router navigation
router.afterEach(function (to) {
router.afterEach(function (to, from) {
if (isTimeTraveling) {
isTimeTraveling = false
return
}
currentPath = to.fullPath
store.commit('router/ROUTE_CHANGED', to)
store.commit('router/ROUTE_CHANGED', { to: to, from: from })
})
}

0 comments on commit 3232eac

Please sign in to comment.