使用不同的模板登录 - Angular 6

时间:2018-05-17 12:07:09

标签: angular

我有这个app.component.html适用于所有页面,除了登录(我不想要导航,侧边栏或页脚)

<app-nav></app-nav>
<app-sidebar></app-sidebar>
<div class="container">
  <router-outlet></router-outlet>
</div>
<app-footer></app-footer>

module.ts

const appRoutes:Routes = [
  {path: '', redirectTo: '/login', pathMatch: 'full'},
  {path: 'login', component:LoginComponent},
  {path: 'dashboard', component:EnvironmentComponent},
  {path: 'docker', component:DockerComponent}
];

如何删除它??

1 个答案:

答案 0 :(得分:0)

您需要根据您当前所在的网址使用* ngIf处理此问题。

<app-sidebar *ngIf="isLoginPage()"></app-sidebar>

然后,

isLoginPage(): boolean {
        const check = this.router.url.indexOf('/login');
        if (check) {
            return false;
        }
    return true;
}