Skip to content

Commit 35a8c6e

Browse files
authored
Feature: 404 page (#180)
closes #154: Added a 404 page when routing within the Angular application
1 parent bcb5c1d commit 35a8c6e

File tree

6 files changed

+61
-2
lines changed

6 files changed

+61
-2
lines changed

src/app/app.routes.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ export const routes: Routes = [
5656
},
5757
{ path: '', component: HomeComponent, title: 'Computing Science Student Society' },
5858
// 404 will go down there
59-
{ path: '**', component: HomeComponent }
59+
{
60+
path: '**',
61+
loadComponent: () =>
62+
import('./pages/not-found/not-found.component').then(m => m.NotFoundComponent),
63+
title: makeTitle('Not Found')
64+
}
6065
] as const;
6166

6267
const BASE_ROUTES = routes.reduce((acc, route) => {

src/app/components/nav-bar/nav-bar.component.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ $navbar-w: 20rem;
4040
background-color: theme.$bg3;
4141
border-right: $border;
4242
z-index: 100;
43-
overflow: scroll;
43+
overflow: auto;
4444

4545
&__heading {
4646
font-size: 1.1rem;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1>Not Found</h1>
2+
<fa-icon [icon]="errorIcon" size="9x"></fa-icon>
3+
<p>The editor could not open the file "{{ this.router.url }}"</p>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
:host {
2+
display: flex;
3+
width: 100%;
4+
height: 100%;
5+
justify-content: center;
6+
align-items: center;
7+
flex-direction: column;
8+
}
9+
10+
fa-icon {
11+
color: hsl(360 64.3% 44.8%);
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { NotFoundComponent } from './not-found.component';
4+
5+
describe('NotFoundComponent', () => {
6+
let component: NotFoundComponent;
7+
let fixture: ComponentFixture<NotFoundComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
imports: [NotFoundComponent]
12+
})
13+
.compileComponents();
14+
15+
fixture = TestBed.createComponent(NotFoundComponent);
16+
component = fixture.componentInstance;
17+
fixture.detectChanges();
18+
});
19+
20+
it('should create', () => {
21+
expect(component).toBeTruthy();
22+
});
23+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
2+
import { Router } from '@angular/router';
3+
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
4+
import { faTriangleExclamation } from '@fortawesome/free-solid-svg-icons';
5+
6+
@Component({
7+
selector: 'cs-not-found',
8+
imports: [FontAwesomeModule],
9+
templateUrl: './not-found.component.html',
10+
styleUrl: './not-found.component.scss',
11+
changeDetection: ChangeDetectionStrategy.OnPush
12+
})
13+
export class NotFoundComponent {
14+
protected errorIcon = faTriangleExclamation;
15+
protected router = inject(Router);
16+
}

0 commit comments

Comments
 (0)