Skip to content

Commit 4e833a6

Browse files
authored
fix(router): remove app from $router.apps array once app destroyed (Fixes vuejs#2639)
Prevent destroyed apps from causing memory leak in `$router.apps` array. Fixes vuejs#2639
1 parent bd41be0 commit 4e833a6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: src/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ export default class VueRouter {
9191

9292
// main app already initialized.
9393
if (this.app) {
94-
return
94+
app.$once('hook:destroyed', () {
95+
// Clean out app from this.apps array once destroyed
96+
const index = this.apps.indexOf(app)
97+
if (index > -1) this.apps.splice(index, 1)
98+
})
99+
return
95100
}
96101

97102
this.app = app

0 commit comments

Comments
 (0)