Skip to content

Add type field to the router event object #43762

Closed
@Smrtnyk

Description

@Smrtnyk

Which @angular/* package(s) are relevant/releated to the feature request?

router

Description

I have a piece of code that gets invoked by user with router as a parameter.
In that code I subscribe to router events.
If an app is minified, constructor names of events are obfuscated and then I need to do some naive checking like

function isNavigationEnd(event: Event): event is NavigationEnd {
    return event["constructor"]["name"] === RouterEvents.NAVIGATION_END
        || ("id" in event
            && typeof event["id"] === "number"
            && !!event["url"]
            && "urlAfterRedirects" in event
            && !!event["urlAfterRedirects"]
            && objectKeys(event).length === 3);
}

I am not so familiar with angular.
The issue I currently have is that I do some action in RouteConfigLoadStart and keep a reference to it
and I clean that reference in NavigationCancel or NavigationEnd
Now for some reason NavigationEnd or NavigationCancel never happens and references keep growing when I enter the RouteConfigLoadStart.
If event constructor names would be preserved I would know which event I am currently working with and could easier do the logic.
Keep in mind that my piece of code is external to the angular app, and it gets called with router as a parameter, so I am not in an non obfuscated environment of the app.

Proposed solution

Add a type field to the event or preserve name of its constructor.

Alternatives considered

I am using an alternative to do the naive checking but some events have same fields and then it could match more events than it should.

Metadata

Metadata

Assignees

Labels

area: routerfeatureIssue that requests a new featurefeature: under considerationFeature request for which voting has completed and the request is now under consideration

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions