-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Closed
Labels
Description
What problem does this feature solve?
In the current version of the router (3.0.1) the global guard beforeEach and the component guard beforeRouteEnter do not provide a valid THIS value. Obviously for beforeEach if you want to access the app property of the router you need a valid THIS in the hook. And since the component is not yet instantiated in beforeRouteEnter you can not access the component as THIS - but at least you should be able to access the router instance (and its app property).
What does the proposed API look like?
I am proposing the following 2 simple changes in the code (file /src/history/base.js):
- in function
confirmTransition()
- invoke the hook with the router instance as THIS
this.pending = route
const iterator = (hook: NavigationGuard, next) => {
if (this.pending !== route) {
return abort()
}
try {
hook.call(this, route, current, (to: any) => { /// <----- proposed change
- in function
bindEnterGuard()
- invoke the hook with the router instance as THIS
return function routeEnterGuard (to, from, next) {
return guard.call(this, to, from, cb => { /// <---- proposed change
next(cb)
if (typeof cb === 'function') {
SeregPie, oles, iamyuu, ianwalter, sebiniemann and 2 more