There are multiple ways to accomplish what you want.
1. Overlay (quick&dirty):
What you did looks quite good. Just don´t try to replace everything - just lay over.
In not-found.component.scss
:host {
position: fixed;
width: 100%;
height: 100%;
}
And do within NotFoundComponent whatever you like. This is defintely not the cleanest solution (just think about screen readers...), but it is quite simple and gets the job done.
2. Service to hide NavBar, Header and Footer (clean, little more complex)
Create an AppService that can control basic app features like showing and hiding top-level components.
Do something like that in app.service.ts:
@Injectable({
providedIn: 'root'
})
export class AppService {
showNavigation$: BehaviorSubject<boolean>;
showHeader$: BehaviorSubject<boolean>;
showFooter$: BehaviorSubject<boolean>;
constructor() {
this.showNavigation$ = new BehaviorSubject<boolean>(true);
this.showHeader$ = new BehaviorSubject<boolean>(true);
this.showFooter$ = new BehaviorSubject<boolean>(true);
}
}
Inject AppService to your AppComponent and bind the components to the fields.
app.component.html:
<div class="background-placeholder">
<app-navbar *ngIf="appService.showNavigation$ | async"></app-navbar>
<!--<app-header *ngIf="appService.showHeader$ | async"></app-header>-->
<router-outlet></router-outlet>
<app-footer *ngIf="appService.showFooter$ | async"></app-footer>
</div>
Inject the service to NotFoundComponent and set the "show" properties to false.
appService.showNavigation.next(false);
appService.showHeader.next(false);
appService.showFooter.next(false);
That is a clean and elegant way to control app-wide features from child components.
3. More hierarchy in navigation (clean, but slightly messes up the url)
Empty your AppComponent so that it contains only the RouterOutlet.
app.component.html:
<div class="background-placeholder">
<router-outlet></router-outlet>
</div>
Now add something like a master-page.
master.component.ts:
<app-navbar></app-navbar>
<!--<app-header></app-header>-->
<router-outlet></router-outlet>
<app-footer></app-footer>
At last define the routes with a little more hierarchy like this:
app-routing.module.ts:
{
path: 'side',
component: MasterComponent,
children: [
{...your actual routes here...},
{
path: '*',
redirectTo: '/not-found'
]
},
{
path: 'not-found',
component: NotFoundComponent
}
That way the master page is not even used for the not-found route.