From c8bb20dda0f1d0f4d3bd408eebf08173052b15fb Mon Sep 17 00:00:00 2001 From: Ken Date: Tue, 13 Dec 2016 13:05:46 -0500 Subject: [PATCH] [29] Store 'from' in state.route --- index.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 8680fb4..b815c8f 100644 --- a/index.js +++ b/index.js @@ -2,14 +2,15 @@ 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 + name: transition.to.name, + path: transition.to.path, + hash: transition.to.hash, + query: transition.to.query, + params: transition.to.params, + fullPath: transition.to.fullPath, + from: transition.from }) } } @@ -33,12 +34,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 }) }) }