Skip to content

Commit f28bf0c

Browse files
committed
avoid triggering beforeRouteUpdate and beforeRouteLeave for instances that are not even created yet (fix #1320)
1 parent f86a8fa commit f28bf0c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/history/base.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,11 @@ function extractUpdateHooks (updated: Array<RouteRecord>): Array<?Function> {
263263
return extractGuards(updated, 'beforeRouteUpdate', bindGuard)
264264
}
265265

266-
function bindGuard (guard: NavigationGuard, instance: _Vue): NavigationGuard {
267-
return function boundRouteGuard () {
268-
return guard.apply(instance, arguments)
266+
function bindGuard (guard: NavigationGuard, instance: ?_Vue): ?NavigationGuard {
267+
if (instance) {
268+
return function boundRouteGuard () {
269+
return guard.apply(instance, arguments)
270+
}
269271
}
270272
}
271273

test/unit/specs/error-handling.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe('error handling', () => {
88
const router = new VueRouter()
99
const err = new Error('foo')
1010
router.beforeEach(() => { throw err })
11+
router.onError(() => {})
1112

1213
const onReady = jasmine.createSpy('ready')
1314
const onError = jasmine.createSpy('error')

0 commit comments

Comments
 (0)