Filtering for NavigationEnd events in Angular 12?

Published

In Angular 11 this works:

this.r.events.pipe(
    filter(event => event instanceof NavigationEnd),
    map((event: NavigationEnd) => event.url == ROUTES.APPLICATION))

However in Angular 12 it produces the error:

Argument of type 'MonoTypeOperatorFunction<Event_2>' is not assignable to parameter of type 'OperatorFunction<Event_2, NavigationEnd>'.
  Type 'Observable<Event_2>' is not assignable to type 'Observable<NavigationEnd>'.
    Type 'Event_2' is not assignable to type 'NavigationEnd'.
      Property 'urlAfterRedirects' is missing in type 'RouterEvent' but required in type 'NavigationEnd'.ts(2345)

Any ideas on how to fix this?

This question has the answer as adding:

"paths": {
    "rxjs": [
      "node_modules/rxjs"
    ],
    "rxjs/*": [
      "node_modules/rxjs/*"
    ]
}

To tsconfig.json. However that did not work …

Source: Angular Questions

Published
Categorized as angular, angular-router, javascript, rxjs, typescript Tagged , , , ,

Answers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq