Skip to content

On bootstrap Angular calls addEventListener for popState but on Destroy it never calls removeEventListener #31546

@ernestlv

Description

@ernestlv

In a SPA sometimes you bootstrap an Angular application then upon browser navigation you have to destroy the current application and bootstrap a new Angular application. All in the sampe page.

In this line, angular register a listener for the "popstate" and "hashchange" event using addEventListener:

https://github.com/angular/angular/blob/master/packages/platform-browser/src/browser/location/browser_platform_location.ts#L45

However, after I destroyed the original application angular never call removeEventListener. Thus when I bootstrap the second application in my SPA the browser fires the new listeners for the "popstate" and "haschange" events plus the original ones.

The number of listeners keeps increasing if I keep navigating back and ford between this applications.

Desired result:

Remove "popstate" and "hashchange" events thru removeEnvetListener when the application is destroyed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimecore: bootstrapfreq1: lowstate: has PRtype: bug/fix

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions