From 6fb1a1ea83ef8e9806b81c86c54ac52805049817 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 10 Jul 2018 12:19:44 +0200 Subject: [PATCH] feat(url): call afterEach hooks after url is ensured Closes #2079 This helps integrating with external scripts and makes more sense as the navigation is finished. However, onComplete callback passed to `router.push` is now called before `afterEach` hooks. This shouldn't be a problem as there's no guarantee provided anywhere in the docs about this --- src/history/base.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/history/base.js b/src/history/base.js index 5b6f199c6..32d6dea89 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -64,9 +64,13 @@ export class History { transitionTo (location: RawLocation, onComplete?: Function, onAbort?: Function) { const route = this.router.match(location, this.current) this.confirmTransition(route, () => { + const prev = this.current this.updateRoute(route) onComplete && onComplete(route) this.ensureURL() + this.router.afterHooks.forEach(hook => { + hook && hook(route, prev) + }) // fire ready cbs once if (!this.ready) { @@ -183,12 +187,8 @@ export class History { } updateRoute (route: Route) { - const prev = this.current this.current = route this.cb && this.cb(route) - this.router.afterHooks.forEach(hook => { - hook && hook(route, prev) - }) } }