Skip to content

Commit 0225e70

Browse files
committed
handle late-rendered <router-view> inside conditional block (fix #109)
1 parent 1272f90 commit 0225e70

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

src/directives/view.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { warn } from '../util'
2+
import { activate } from '../pipeline'
23

34
export default function (Vue) {
45

@@ -58,6 +59,19 @@ export default function (Vue) {
5859
// parent's has resolved.
5960
parentView.childView = this
6061
}
62+
63+
// handle late-rendered view
64+
// two possibilities:
65+
// 1. root view rendered after transition has been
66+
// validated;
67+
// 2. child view rendered after parent view has been
68+
// activated.
69+
var transition = route.router._currentTransition
70+
if ((!parentView && transition.done) ||
71+
(parentView && parentView.activated)) {
72+
var depth = parentView ? parentView.depth + 1 : 0
73+
activate(this, transition, depth)
74+
}
6175
},
6276

6377
unbind: function () {

src/pipeline.js

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ export function activate (view, transition, depth, cb) {
113113
let dataHook = getRouteConfig(Component, 'data')
114114
let waitForData = getRouteConfig(Component, 'waitForData')
115115

116+
view.depth = depth
117+
view.activated = false
118+
116119
// unbuild current component. this step also destroys
117120
// and removes all nested child views.
118121
view.unbuild(true)
@@ -152,6 +155,7 @@ export function activate (view, transition, depth, cb) {
152155

153156
// called after activation hook is resolved
154157
let afterActivate = () => {
158+
view.activated = true
155159
// activate the child view
156160
if (view.childView) {
157161
exports.activate(view.childView, transition, depth + 1)

src/router/internal.js

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export default function (Vue, Router) {
208208
from: transition.from
209209
}))
210210
}
211+
this._currentTransition.done = true
211212
}
212213

213214
/**

src/transition.js

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default class RouteTransition {
2222
this.from = from
2323
this.next = null
2424
this.aborted = false
25+
this.done = false
2526

2627
// start by determine the queues
2728

test/unit/specs/core.js

+41
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,47 @@ describe('Core', function () {
681681
}, wait * 2)
682682
}, 0)
683683
})
684+
685+
it('late-rendered view inside conditional blocks', function (done) {
686+
var component = {
687+
template:
688+
'<div>' +
689+
'<div v-if="show">' +
690+
'<router-view></router-view>' +
691+
'</div>' +
692+
'</div>',
693+
data: function () {
694+
return { show: false }
695+
},
696+
compiled: function () {
697+
var self = this
698+
setTimeout(function () {
699+
self.show = true
700+
}, wait)
701+
}
702+
}
703+
router = new Router({
704+
abstract: true
705+
})
706+
router.map({
707+
'/a': {
708+
component: component,
709+
subRoutes: {
710+
'/b': {
711+
component: {
712+
template: 'Rendered!'
713+
}
714+
}
715+
}
716+
}
717+
})
718+
router.start(Vue.extend(component), el)
719+
router.go('/a/b')
720+
setTimeout(function () {
721+
expect(router.app.$el.textContent).toBe('Rendered!')
722+
done()
723+
}, wait * 3)
724+
})
684725
}
685726

686727
function assertRoutes (matches, options, done) {

0 commit comments

Comments
 (0)