How To Setup 404 Page In Angular 12

ng generate component page_not_found
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>How To Setup 404 Page In Angular 12 - Websolutionstuff</title>
</head>
<body>
<h1>Error 404</h1>
<p>Page Not Found</p>
</body>
</html>
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard/dashboard.component';
import { PageNotFoundComponent } from './page_not_found/page_not_found.component';

const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'dashboard', component: DashboardComponent },

// Route for 404 request
{ path: 'page_not_found', component: PageNotFoundComponent },
{ path: '**', component: PageNotFoundComponent },
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule { }
ng serve
http://localhost:4200

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Websolutionstuff

Websolutionstuff

96 Followers

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API.