I think you can use "ng-template" for this;
Firstly create a routing module like this;
const routes: Routes = [
{
path: 'login',
component: LoginComponent,
data: { showRootComponents: false }
},
{
path: 'home',
component: HomeComponent,
data: { showRootComponents: true }
}
]
export const AppRoutingModule = RouterModule.forRoot(routes);
And import this in to your AppModule;
@NgModule({
declarations: [
AppComponent,
HomeComponent,
LoginComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpModule,
FormsModule,
ReactiveFormsModule
]
bootstrap: [AppComponent]
})
export class AppModule { }
Then in your root component;
withoutRootComponents:boolean
public constructor(private activatedRoute:ActivatedRoute) {
this.withoutRootComponents = activatedRoute.snapshot.data['showRootComponents']);
}
and 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>