title: Angular 4 Route Parameter Validation
body: <p>I have a route with a parameter userID</p>
  
  <pre><code>{
      path: "edit/:userID",
      component: EditUserComponent,
      canActivate: [AuthGuard]
    },
  </code></pre>
  
  <p>and on the edit-user-component.ts</p>
  
  <pre><code>    this.requestID = this.route.snapshot.params.requestID;
          this.formService
            .getPendingRequest(this.requestID)
            .subscribe((form: any) =&gt; {
              form.forEach(element =&gt; {
                if (element) {
                  this.editRequest.patchValue({
                    userID: element.userID,
                    userName:element.username,               
  });
                } else {
                  this.router.navigate(["view"]);
                }
  </code></pre>
  
  <p>Now I have unique ID for every user. like I can visit <strong>localhost:4200/edit/12</strong> but if I go to <strong>localhost:4200/edit/13</strong> which does not exist in my mongoDB I want them redirect the page to 404 or main homePage.</p>