Skip to content

Commit fecd631

Browse files
committed
fix: should always abort any ongoing transition on match
1 parent fa95523 commit fecd631

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

src/index.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -380,22 +380,38 @@ class Router {
380380
return
381381
}
382382

383-
let prevRoute = this._currentRoute
384-
let prevTransition = this._currentTransition
383+
let currentRoute = this._currentRoute
384+
let currentTransition = this._currentTransition
385385

386-
// do nothing if going to the same route.
387386
// the route only changes when a transition successfully
388387
// reaches activation; we don't need to do anything
389388
// if an ongoing transition is aborted during validation
390389
// phase.
391-
if (prevTransition && path === prevRoute.path) {
392-
return
390+
if (currentTransition) {
391+
if (currentTransition.to.path === path) {
392+
// do nothing if we have an active transition going to the same path
393+
return
394+
} else if (currentRoute.path === path) {
395+
// We are going to the same path, but we also have an ongoing but
396+
// not-yet-validated transition. Abort that transition and reset to
397+
// prev transition.
398+
currentTransition.aborted = true
399+
this._currentTransition = this._prevTransition
400+
return
401+
} else {
402+
// going to a totally different path. abort ongoing transition.
403+
currentTransition.aborted = true
404+
}
393405
}
394406

395407
// construct new route and transition context
396408
let route = new Route(path, this)
397-
let transition = new Transition(this, route, prevRoute)
398-
this._prevTransition = prevTransition
409+
let transition = new Transition(this, route, currentRoute)
410+
411+
// current transition is updated right now.
412+
// however, current route will only be updated after the transition has
413+
// been validated.
414+
this._prevTransition = currentTransition
399415
this._currentTransition = transition
400416

401417
if (!this.app) {
@@ -448,12 +464,6 @@ class Router {
448464
*/
449465

450466
_onTransitionValidated (transition) {
451-
// now that this one is validated, we can abort
452-
// the previous transition.
453-
let prevTransition = this._prevTransition
454-
if (prevTransition) {
455-
prevTransition.aborted = true
456-
}
457467
// set current route
458468
let route = this._currentRoute = transition.to
459469
// update route context for all children
@@ -569,12 +579,6 @@ Router.install = function (externalVue) {
569579
View(Vue)
570580
Link(Vue)
571581
util.Vue = Vue
572-
// 1.0 only: enable route mixins
573-
var strats = Vue.config.optionMergeStrategies
574-
if (strats) {
575-
// use the same merge strategy as methods (object hash)
576-
strats.route = strats.methods
577-
}
578582
Router.installed = true
579583
}
580584

src/transition.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ export default class RouteTransition {
206206
let nextCalled = false
207207

208208
// abort the transition
209-
let abort = (back) => {
209+
let abort = () => {
210210
cleanup && cleanup()
211-
transition.abort(back)
211+
transition.abort()
212212
}
213213

214214
// handle errors

0 commit comments

Comments
 (0)