Skip to content

Commit 2177e45

Browse files
committed
fix $route update timing (fix #75)
1 parent bee240c commit 2177e45

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/router/internal.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,33 @@ module.exports = function (Vue, Router) {
194194
}
195195

196196
/**
197-
* Handle stuff after the transition.
197+
* Switch the current route to a new one.
198+
* This is called by the transition object when the
199+
* validation of a route has succeeded.
198200
*
199201
* @param {Route} route
200-
* @param {Object} [state]
201-
* @param {String} [anchor]
202202
*/
203203

204-
p._postTransition = function (route, state, anchor) {
204+
p._updateRoute = function (route) {
205+
this._currentRoute = route
205206
// update route context for all children
206207
if (this.app.$route !== route) {
207208
this.app.$route = route
208209
this._children.forEach(function (child) {
209210
child.$route = route
210211
})
211212
}
213+
}
214+
215+
/**
216+
* Handle stuff after the transition.
217+
*
218+
* @param {Route} route
219+
* @param {Object} [state]
220+
* @param {String} [anchor]
221+
*/
212222

223+
p._postTransition = function (route, state, anchor) {
213224
// handle scroll positions
214225
// saved scroll positions take priority
215226
// then we check if the path has an anchor

src/transition.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,16 @@ p.start = function (cb) {
123123
transition.runQueue(daq, pipeline.canDeactivate, function canActivatePhase () {
124124
transition.runQueue(aq, pipeline.canActivate, function deactivatePhase () {
125125
transition.runQueue(daq, pipeline.deactivate, function activatePhase () {
126-
// validation complete. change the current route.
127-
transition.router._currentRoute = transition.to
126+
// Validation phase is now over! The new route is valid.
127+
128+
// Update router current route
129+
transition.router._updateRoute(transition.to)
130+
128131
// trigger reuse for all reused views
129132
reuseQueue && reuseQueue.forEach(function (view) {
130133
pipeline.reuse(view, transition)
131134
})
135+
132136
// the root of the chain that needs to be replaced
133137
// is the top-most non-reusable view.
134138
if (daq.length) {

test/unit/.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
},
66

77
"globals": {
8+
"isIE": true,
89
"isIE9": true,
910
"jasmine": true,
1011
"describe": true,

0 commit comments

Comments
 (0)