angular2 - Check user login
<p>I'm starting to learn all about angular 2 and currently have a problem. I have defined these routes in my application:</p>

<pre><code>const appRoutes: Routes = [
  {path: 'start',
    component: StartComponent,
    children:[{path: '' },
      {
        path:'nested', component:NestedTestComponent
      }
    ]},
  {path: '', component:LoginFormComponent}
];
</code></pre>

<p>There is the "base" path which shows a login form, after the user entered credentials (and they are correct), the user will be directed to "start" and this as a nested route "nested".
This works great. But I want to somehow restrict the user to visit "start" and "nested" if the user is not logged in. Because that's currently possible with just entering this as an url.</p>

<p>My index.html looks like this:</p>

<pre><code>&lt;body&gt;
  &lt;app-root&gt;Loading...&lt;/app-root&gt;
&lt;/body&gt;
</code></pre>

<p>app.component:</p>

<pre><code>@Component({
  selector: "app-root",
  template: `
        &lt;router-outlet&gt;&lt;/router-outlet&gt;
        `,
  styleUrls: ['./app.component.css']
})
</code></pre>

<p>start.component</p>

<pre><code>&lt;nav&gt;
    &lt;div class="nav-wrapper"&gt;
      &lt;a href="#" class="brand-logo center"&gt;&lt;/a&gt;
      &lt;ul id="nav-mobile" class="right hide-on-med-and-down"&gt;
        &lt;li&gt;&lt;a (click)="logout()"&gt;Logout&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/nav&gt;
  &lt;router-outlet&gt;&lt;/router-outlet&gt;
</code></pre>

<p>Since everything is somehow nested in the  my approach was to check in the app.component if the user is logged in with this:</p>

<pre><code>export class AppComponent {



  constructor(af:AngularFire, router:Router){
    if(af.auth.getAuth() == null){
      //redirect to start
      console.log('redirect to login');
      router.navigate(['']);
    }else{
      console.log('not redirect to login');
    }
  }
}
</code></pre>

<p>This works and correctly detects if user should be redirected or not. However, the <code>router.navigate(['']);</code> does not work. It just does nothing.</p>