title: Angular: Unable to subscribe to the latest value of BehaviorSubject in sibling component through routes
body: <p>I'm trying to trigger an event in component B through it's sibling component A. I have routes configured in this way</p>
  
  <pre><code>export const routes: Routes = [
      { path: '', component: FileUploadComponent,
        children: [
          { path: '', redirectTo: 'zipUpload', pathMatch: 'full' },
          { path: 'zipUpload', component: ZipFileUploadComponent },
          { path: 'reportsView', component: ReportsViewComponent }
        ]
      }
  ];
  </code></pre>
  
  <p>I have written BehaviorSubject logic in the service class. Service is AppModule level.</p>
  
  <pre><code>@Injectable()
  export class AppState {
  
    public canShowAlerts$ = new BehaviorSubject&lt;boolean&gt;(false);
    public showAlerts(booleanData: boolean): void {
      this.canShowAlerts$.next(booleanData);
    }
  </code></pre>
  
  <p>In component A, after subscribing to an API response and if the response is success, I'm setting the BehaviorSubject value to true and later I'm navigating to component B and want to display a success alert.</p>
  
  <p>Component A</p>
  
  <pre><code>this.someService.uploadFile(data)
      .subscribe(
        (response) =&gt; {
          if (response === 'Success') {
           this.appState.showAlerts(true);
           this.router.navigate(['../reportsView'],  {relativeTo: this.route});
          }
        },
        (error) =&gt; {
          this.errors = error;
        }); 
  </code></pre>
  
  <p>Component B</p>
  
  <pre><code>constructor(private appState: AppState) {
          this.appState.canShowAlerts$.subscribe(
              (response) =&gt; {
                  if (response === true) {
                      this.myData = 'Successfully uploaded zip files';
                  }
              }
          )}
  </code></pre>
  
  <p>Problem is, Component B is not fetching the true value set in component A and its fetching the initial false value. Is this because value is set in it's sibling component? Or any other issue? Please suggest.</p>