As far as I understand, all errors are redirected to the /error path. Right? The best option is to show the error page on the path where the user went. At the moment (Angular 13) there is no such built-in feature, so we have to come up with workarounds.
It is an interesting point. The only problem I see with this approach is the need to write an error handler inside every route resolver. That kind of makes the components lose their purpose. I believe all the user needs is to navigate back to the page where he/she came from, and for that we can make use of @angular/common's Location class.
Another approach is - (if we want to stay on the same page) - is to use { skipLocationChange: true } when we navigate to /error.
That kind of makes the components lose their purpose.
No, it's not. On the contrary, we can use the components to the fullest, because we can use the appropriate component for the error handler:
<ng-container*ngIf="!httpErrorResponse">
Current component code here
</ng-container><cst-http-errors[httpErrorResponse]="httpErrorResponse"></cst-http-errors>
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
As far as I understand, all errors are redirected to the
/error
path. Right? The best option is to show the error page on the path where the user went. At the moment (Angular 13) there is no such built-in feature, so we have to come up with workarounds.See solution on stackblitz
It is an interesting point. The only problem I see with this approach is the need to write an error handler inside every route resolver. That kind of makes the components lose their purpose. I believe all the user needs is to navigate back to the page where he/she came from, and for that we can make use of
@angular/common
'sLocation
class.Another approach is - (if we want to stay on the same page) - is to use
{ skipLocationChange: true }
when we navigate to/error
.No, it's not. On the contrary, we can use the components to the fullest, because we can use the appropriate component for the error handler: