Skip to content

Commit 8f7c970

Browse files
committed
tweak route state setting
1 parent 3a6b4ff commit 8f7c970

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

index.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@ exports.sync = function (store, router, options) {
55
state: {},
66
mutations: {
77
'router/ROUTE_CHANGED': function (state, transition) {
8-
store.state[moduleName] = Object.freeze({
9-
name: transition.to.name,
10-
path: transition.to.path,
11-
hash: transition.to.hash,
12-
query: transition.to.query,
13-
params: transition.to.params,
14-
fullPath: transition.to.fullPath,
15-
meta: transition.to.meta,
16-
from: transition.from
17-
})
8+
store.state[moduleName] = cloneRoute(transition.to, transition.from)
189
}
1910
}
2011
})
@@ -46,3 +37,19 @@ exports.sync = function (store, router, options) {
4637
store.commit('router/ROUTE_CHANGED', { to: to, from: from })
4738
})
4839
}
40+
41+
function cloneRoute (to, from) {
42+
const clone = {
43+
name: to.name,
44+
path: to.path,
45+
hash: to.hash,
46+
query: to.query,
47+
params: to.params,
48+
fullPath: to.fullPath,
49+
meta: to.meta
50+
}
51+
if (from) {
52+
clone.from = cloneRoute(from)
53+
}
54+
return Object.freeze(clone)
55+
}

0 commit comments

Comments
 (0)