Angular Reactive Boolean Navigation State | Task

Ole Ersoy
Mar - 22  -  1 min

Scenario

We want a Observable<boolean> that is true when the user navigates to /application.

Approach

constructor(private r: Router) {
  this.isApplicationShowing$ =
    this.r.events.pipe(
      filter(event => event instanceof NavigationEnd),
      map((event: NavigationEnd) => event.url == this.APPLICATION_ROUTE ))
}