Search code examples
angularangular-ui-routerangular-ng-if

*ngIf for all sub routes


I want do figure out how I can show a container with *ngIf for all sub routes.

Like for:

<div *ngIf="router.url === /page/**"></div>

So this container is shown when I am at "page" and also for all subpages of "page".

Thanks for your help


Solution

  •     public currentLink: string;
    
        constructor(private router: Router){
    
            this.currentLink = this.router.url;
    
       }
       if(this.currentLink.startsWith('/page/')) this.flag = true;
       else this.flag = false;
    
      <div *ngIf="flag"></div>
    
    > you can get the URL using observable also