Skip to content

Handling 404 Errors and Redirects

Angular allows redirecting routes and handling unknown paths.

Redirect example:

const routes = [{ path: "", redirectTo: "/home", pathMatch: "full" }];

404 handling using a wildcard route:

const routes = [
{ path: "home", component: HomeComponent },
{ path: "**", component: PageNotFoundComponent },
];

The wildcard route must always be placed last in the routing configuration.