Skip to content

Commit a5554a8

Browse files
committed
fix route hook extraction for extended constructors
1 parent 1f18055 commit a5554a8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/history/base.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,17 @@ function resolveQueue (
147147
}
148148
}
149149

150+
function extractGuard (def, key) {
151+
if (typeof def === 'function' && def.options) {
152+
return def.options[key]
153+
} else if (def) {
154+
return def[key]
155+
}
156+
}
157+
150158
function extractLeaveGuards (matched: Array<RouteRecord>): Array<?Function> {
151159
return flatMapComponents(matched, (def, instance) => {
152-
const guard = def && def.beforeRouteLeave
160+
const guard = extractGuard(def, 'beforeRouteLeave')
153161
if (guard) {
154162
return function routeLeaveGuard () {
155163
return guard.apply(instance, arguments)
@@ -164,7 +172,7 @@ function extractEnterGuards (
164172
isValid: () => boolean
165173
): Array<?Function> {
166174
return flatMapComponents(matched, (def, _, match, key) => {
167-
const guard = def && def.beforeRouteEnter
175+
const guard = extractGuard(def, 'beforeRouteEnter')
168176
if (guard) {
169177
return function routeEnterGuard (to, from, next) {
170178
return guard(to, from, cb => {

0 commit comments

Comments
 (0)