How to reload Angular 2 app after user is logout
<p>I want to reload my Angular 2 app after a user clicks a logout button, that is I want to clean all current data in the app and to load a sign in form from the server.</p>

<p>Now, after clicking a logout button, I am getting the answer from the server (with sign in form in it) in my subscribe method, but I do not know how to clean current app's data and to load sign in form.</p>

<p>Can anybody help me?</p>

<p>This is my main class AppComponent</p>

<pre><code>import {Component}          from 'angular2/core';
import {OnInit}             from "angular2/core";
import {Router}             from "angular2/router";
import {RouteConfig}        from "angular2/router";
import {AuthRouteOutlet}    from "./common/directives/auth-router-outlet.directive";
import {AuthService}        from "./common/services/auth.service";
import {DashboardComponent} from "./common/components/dashboard.component";

@Component({
  selector: 'my-app',
  template: `
    &lt;auth-router-outlet&gt;&lt;/auth-router-outlet&gt;
  `,
  directives: [AuthRouteOutlet, DashboardComponent]
})
@RouteConfig([
  {path: '/dashboard/...', name: 'Dashboard', component: DashboardComponent, useAsDefault: true}

])
export class AppComponent implements OnInit {
  constructor(
      private _router: Router,
      private _authService: AuthService
  ) {}

  ngOnInit():any {
    var self = this;

    this._authService.getLoggedOutEvent().subscribe(function(next) {
      //console.log('AppComponent OnEmit: ' + JSON.stringify(next));
      self._router.navigateByUrl('/', true);
    });
  }
}
</code></pre>

<p>This is my service. I send the logout request from here.</p>

<pre><code>import {Injectable, EventEmitter} from 'angular2/core';
import {User} from "../models/user.interface";
import {Http} from "angular2/http";
import {Observable} from "rxjs/Observable";
import {Headers} from "angular2/http";

@Injectable()
export class AuthService {

  private _userLoggedOut = new EventEmitter&lt;any&gt;();

  constructor(private _http: Http) {}

  getLoggedOutEvent(): EventEmitter&lt;any&gt; {
      return this._userLoggedOut;
  }

  logout(): Observable&lt;any&gt;{
    return this._http.get('/logout');
  }
}
</code></pre>

<p>And this is my component from which I invoke the logout method.</p>

<pre><code>import {Component}    from "angular2/core";
import {ROUTER_DIRECTIVES, Router} from "angular2/router";
import {AuthService}  from "../services/auth.service";

@Component({
  selector: 'mdm-header-bar',
  template: `
    &lt;header&gt;
      &lt;nav id="mdm-header-bar" &gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;a (click)="addComponent()" title="Add component"&gt;&lt;i class="fa fa-plus-circle"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a (click)="settings()" title="Settings"&gt;&lt;i class="fa fa-cog"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a (click)="help()" title="Help"&gt;&lt;i class="fa fa-question-circle"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a (click)="logout()" title="Logout"&gt;&lt;i class="fa fa-sign-out"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/nav&gt;
    &lt;/header&gt;
  `,
  directives: [ROUTER_DIRECTIVES]
})
export class HeaderComponent {
  constructor(private _authService: AuthService) {}

  logout() {
    var self = this;
    this._authService.logout()
        .subscribe(function(next) {
          self._authService.getLoggedOutEvent().emit(next);
        }, function(exception){
          console.log('HeaderComponent OnException: ' + exception);
        }, function() {
          console.log('HeaderComponent OnCompleted ');
        });
  }

}
</code></pre>

<p>When I load app's main page the first time (I send the request to localhost:3000), the server checks if I authenticated and if not, it redirects me to the localhost:3000/signin page. After authentication the server sends me the main page: localhost:3000</p>

<p>When I send the logout request, the server logouts me and sends back an answer with localhost:3000/signin page, because I am not logged in already.</p>

<p>I get this page from the server in my logout(...).subscribe(...) method, but I do not know how to unload the current page (app) and get browser to load this page.</p>