Skip to content

Commit 0d0853d

Browse files
IsmaestroIsmael Ramos
authored andcommitted
feat(404): added 404 page error
1 parent 2ca26f9 commit 0d0853d

File tree

11 files changed

+87
-4
lines changed

11 files changed

+87
-4
lines changed

src/app/app-routing.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ import {RouterModule, Routes} from '@angular/router';
33

44
import {HeroTopComponent} from './heroes/hero-top/hero-top.component';
55
import {AppConfig} from './config/app.config';
6+
import {Error404Component} from './core/error404/error-404.component';
67

78
const routes: Routes = [
89
{path: '', redirectTo: '/', pathMatch: 'full'},
910
{path: '', component: HeroTopComponent},
10-
{path: AppConfig.routes.heroes, loadChildren: './heroes/heroes.module#HeroesModule'}
11+
{path: AppConfig.routes.heroes, loadChildren: './heroes/heroes.module#HeroesModule'},
12+
{path: AppConfig.routes.error404, component: Error404Component},
13+
14+
// otherwise redirect to 404
15+
{path: '**', redirectTo: '/' + AppConfig.routes.error404}
1116
];
1217

1318
@NgModule({

src/app/config/app.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export let APP_CONFIG = new InjectionToken('app.config');
66

77
export const AppConfig: IAppConfig = {
88
routes: {
9-
heroes: 'heroes'
9+
heroes: 'heroes',
10+
error404: '404'
1011
},
1112
endpoints: {
1213
heroes: 'https://nodejs-example-app.herokuapp.com/heroes'

src/app/core/core.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {FooterComponent} from './footer/footer.component';
1010
import {SharedModule} from '../shared/modules/shared.module';
1111
import {RouterModule} from '@angular/router';
1212
import {SearchBarComponent} from './search-bar/search-bar.component';
13+
import {Error404Component} from './error404/error-404.component';
1314

1415

1516
@NgModule({
@@ -27,7 +28,8 @@ import {SearchBarComponent} from './search-bar/search-bar.component';
2728
declarations: [
2829
NavComponent,
2930
FooterComponent,
30-
SearchBarComponent
31+
SearchBarComponent,
32+
Error404Component
3133
],
3234
providers: [
3335
LoggerService
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1 class="section-title">{{'error404' | translate}}</h1>
2+
<p class="explanation">{{'mayTheForce' | translate}}</p>
3+
<img src="assets/images/404.gif">
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
img {
2+
margin: 0 auto;
3+
display: block;
4+
}
5+
6+
.explanation {
7+
margin: 1em 0;
8+
text-align: center;
9+
font-size: 1.2em;
10+
font-weight: 300;
11+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {async, TestBed} from '@angular/core/testing';
2+
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
3+
import {TranslateModule} from '@ngx-translate/core';
4+
import {APP_CONFIG, AppConfig} from '../../config/app.config';
5+
import {HeroService} from '../../heroes/shared/hero.service';
6+
import {MaterialModule} from '../../shared/modules/material.module';
7+
import {ProgressBarService} from '../../shared/services/progress-bar.service';
8+
import {TestsModule} from '../../shared/modules/tests.module';
9+
import {Error404Component} from './error-404.component';
10+
11+
fdescribe('Error404Component', () => {
12+
let fixture;
13+
let component;
14+
let progressBarService;
15+
16+
beforeEach(async(() => {
17+
TestBed.configureTestingModule({
18+
imports: [
19+
TestsModule,
20+
TranslateModule.forRoot(),
21+
MaterialModule
22+
],
23+
declarations: [
24+
Error404Component
25+
],
26+
providers: [
27+
{provide: APP_CONFIG, useValue: AppConfig},
28+
HeroService,
29+
ProgressBarService
30+
],
31+
schemas: [CUSTOM_ELEMENTS_SCHEMA]
32+
}).compileComponents();
33+
34+
fixture = TestBed.createComponent(Error404Component);
35+
component = fixture.debugElement.componentInstance;
36+
progressBarService = TestBed.get(ProgressBarService);
37+
}));
38+
39+
it('should create nav component', (() => {
40+
expect(component).toBeTruthy();
41+
}));
42+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-error-404',
5+
templateUrl: './error-404.component.html',
6+
styleUrls: ['./error-404.component.scss']
7+
})
8+
9+
export class Error404Component {
10+
constructor() {
11+
}
12+
}

src/assets/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@
4747
"yes": "Yes",
4848
"heroRemoved": "Hero has gone :(",
4949
"heroDetail": "Hero detail",
50+
"error404": "404 Error",
51+
"mayTheForce": "May the force be with you",
5052
"updateBrowser": "You are using an old browser, please update it and reload the page."
5153
}

src/assets/i18n/es.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@
4747
"yes": "Yes",
4848
"heroRemoved": "El heroe nos ha dejado :(",
4949
"heroDetail": "Detalle del heroe",
50+
"error404": "Error 404",
51+
"mayTheForce": "Que la fuerza te acompañe",
5052
"updateBrowser": "Estas usando un navegador antiguo, por favor actualiza la versión y recarga la página."
5153
}

src/assets/i18n/pt-br.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@
4646
"no": "Não",
4747
"yes": "Sim",
4848
"heroRemoved": "O herói se foi :(",
49-
"heroDetail": "Detalhes do herói"
49+
"heroDetail": "Detalhes do herói",
50+
"error404": "Erro 404",
51+
"mayTheForce": "Que a força te acompanhe",
52+
"updateBrowser": "Você está usando um navegador antigo, atualize a versão e recarregue a página."
5053
}

0 commit comments

Comments
 (0)