Skip to content

Commit

Permalink
feat(url): call afterEach hooks after url is ensured
Browse files Browse the repository at this point in the history
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
  • Loading branch information
posva committed Jul 10, 2018
1 parent 4df1e94 commit 6fb1a1e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/history/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}
}

Expand Down

0 comments on commit 6fb1a1e

Please sign in to comment.