I have so many url, and sometimes I can not handle all error with
core.js:6479 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'test' Error: Cannot match any routes. URL Segment: 'test'
Does someone knows some common solution to handle this kind of error, and redirect user to 404, somekind of interceptor or something else, thank
CodePudding user response:
You can add the wild card in route, If path does not match then it will redirect to error component which will be common for handling error page.
eg.
const routes: Routes = [
{ path: 'about', component: AboutComponent },
{ path: '', redirectTo: '/about', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent }, // Wildcard route for a 404 page
];
Here,
If a non existent page is called, then the first two route gets failed. But, the final wildcard route will succeed and the PageNotFoundComponent gets called.