Breaking News

LightBlog

Wednesday 7 March 2018

Angular 2/5 - 404 Error Handling

In this article I'll explain you how to handling 404 error



Starting a new project
First use your terminal to navigate to a directory that will be the parent directory of your project, then run this command:
ng new app-name

Serve project

ng serve

Add a 404 page
ng g component notfound

Change in app routing

import { NotfoundComponent } from './notfound/notfound.component';

const routes: Routes = [
    { path: '**',  component: NotfoundComponent },
  ]

Change in notfound.component.html
<h1>404</h1>

No comments:

Post a Comment