Currently, I have a predefined route that includes a parameter called userID.
{
path: "edit/:userID",
component: EditUserComponent,
canActivate: [AuthGuard]
},
Within the edit-user-component.ts file, the following logic is implemented:
this.requestID = this.route.snapshot.params.requestID;
this.formService
.getPendingRequest(this.requestID)
.subscribe((form: any) => {
form.forEach(element => {
if (element) {
this.editRequest.patchValue({
userID: element.userID,
userName:element.username,
});
} else {
this.router.navigate(["view"]);
}
As a result, unique ID's are assigned to every user. For example, I can access localhost:4200/edit/12. However, if I attempt to visit localhost:4200/edit/13 for a userID that does not exist in the MongoDB, I would like the page to automatically redirect to a 404 error page or the main homepage.