Hide elements based on routing in Angular2 rc1
Simply check the router.url
in the template:
my.component.ts
...constructor(public router: Router){}...
my.component.html
<div *ngIf="router.url != '/login'"> <h2>Not in login!</h2></div>
This is what I did for Angular2 RC5 router :
import {Router} from '@angular/router';public location = '' ;constructor(private _router : Router) { this.location = _router.url;}
In HTML :
<div *ngIf = "location == '/home' "></div>
Hope this helps !
I was able to find the syntax I needed for rc1 buried in a comment here: In Angular 2 how do you determine the active route?
<div *ngIf="!router.urlTree.contains(router.createUrlTree(['/login']))">