Я думаю, вы можете использовать для этого «ng-template»;
Сначала создайте модуль маршрутизации, подобный этому;
const routes: Routes = [
{
path: 'login',
component: LoginComponent,
data: { showRootComponents: false }
},
{
path: 'home',
component: HomeComponent,
data: { showRootComponents: true }
}
]
export const AppRoutingModule = RouterModule.forRoot(routes);
И импортируйте его в свой AppModule;
@NgModule({
declarations: [
AppComponent,
HomeComponent,
LoginComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpModule,
FormsModule,
ReactiveFormsModule
]
bootstrap: [AppComponent]
})
export class AppModule { }
Тогда в вашем корневом компоненте;
withoutRootComponents:boolean
public constructor(private activatedRoute:ActivatedRoute) {
this.withoutRootComponents = activatedRoute.snapshot.data['showRootComponents']);
}
и html;
<ng-template [ngIf]="!withoutRootComponents">
<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>
</ng-template>
<ng-template [ngIf]="withoutRootComponents">
<router-outlet></router-outlet>
</ng-template>