Skip to content

Commit a74c3a3

Browse files
committed
router.start(): add callback after app rendered
1 parent 787e226 commit a74c3a3

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class Router {
5454

5555
// state
5656
this._started = false
57+
this._startCb = null
5758
this._currentRoute = {}
5859
this._currentTransition = null
5960
this._previousTransition = null

src/router/api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,17 @@ export default function (Vue, Router) {
109109
*
110110
* @param {VueConstructor} App
111111
* @param {String|Element} container
112+
* @param {Function} [cb]
112113
*/
113114

114-
Router.prototype.start = function (App, container) {
115+
Router.prototype.start = function (App, container, cb) {
115116
/* istanbul ignore if */
116117
if (this._started) {
117118
warn('already started.')
118119
return
119120
}
120121
this._started = true
122+
this._startCb = cb
121123
if (!this.app) {
122124
/* istanbul ignore if */
123125
if (!App || !container) {

src/router/internal.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ export default function (Vue, Router) {
170170
startTransition()
171171
}
172172

173+
if (!this._rendered && this._startCb) {
174+
this._startCb.call(null)
175+
}
176+
173177
// HACK:
174178
// set rendered to true after the transition start, so
175179
// that components that are acitvated synchronously know

test/unit/specs/core.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ describe('Core', function () {
2020
var App = Vue.extend({
2121
template: '<div><router-view></router-view></div>'
2222
})
23-
router.start(App, el)
23+
var cb = jasmine.createSpy()
24+
router.start(App, el, function () {
25+
expect(router.app).toBeTruthy()
26+
cb()
27+
})
28+
expect(cb).toHaveBeenCalled()
2429
assertRoutes([
2530
['/a', 'AAA'],
2631
['/b', 'BBB'],

0 commit comments

Comments
 (0)