From 836c009d08e62af216956a8bd5288c7c1d92fbe6 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Tue, 5 Mar 2019 03:37:38 -0400 Subject: [PATCH] fix(router): remove app from $router.apps array once app destroyed (Fixes #2639) Prevent destroyed apps from causing memory leak in `$router.apps` array. Fixes #2639 --- src/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 69c3cc0c8..5c9d9abfc 100644 --- a/src/index.js +++ b/src/index.js @@ -91,7 +91,12 @@ export default class VueRouter { // main app already initialized. if (this.app) { - return + app.$once('hook:destroyed', () { + // Clean out app from this.apps array once destroyed + const index = this.apps.indexOf(app) + if (index > -1) this.apps.splice(index, 1) + }) + return } this.app = app