Skip to content

fix: reset history.current on destroy app #3297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/history/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,17 @@ export class History {
// Default implementation is empty
}

teardownListeners () {
teardown () {
// clean up event listeners
// https://github.com/vuejs/vue-router/issues/2341
this.listeners.forEach(cleanupListener => {
cleanupListener()
})
this.listeners = []

// reset current history route
// https://github.com/vuejs/vue-router/issues/3294
this.current = START
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ export default class VueRouter {
// we do not release the router so it can be reused
if (this.app === app) this.app = this.apps[0] || null

if (!this.app) {
// clean up event listeners
// https://github.com/vuejs/vue-router/issues/2341
this.history.teardownListeners()
}
if (!this.app) this.history.teardown()
})

// main app previously initialized
Expand Down