title: How to redirect to another component after checking conditions in angular 8?
body: <p>I am new to Angular 8 and i am making a login component and after entering username password i want to redirect to another component using route thats my code i have done this much :</p>
  
  <p>my login component.ts:</p>
  
  <pre><code>       import { Component, OnInit } from '@angular/core';
         import{FormGroup,FormBuilder,Validators} from '@angular/forms'
  
  
  @Component({
    selector: 'app-login',
    templateUrl: './login.component.html',
    styleUrls: ['./login.component.css']
  })
  export class LoginComponent implements OnInit {
    myForm:FormGroup
    submitted=false;
    _baseURL : string;
    formvalid: boolean;
     user:string;
     pwd:string;
    constructor(private formbuilder:FormBuilder){}
  
  
    ngOnInit(){
      this.myForm = this.formbuilder.group({
      username:['',Validators.required],
      password:['',[Validators.required,Validators.pattern("^(?=.*?[a-z])(.{13,}|(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[#?!@$%^&amp;*-]).{8,12})$")]]
      });
      this._baseURL="";
      this.formvalid=false;
    }
  
    Submitme(){
      this.submitted = true;
  
      if (this.myForm.invalid) {
        this.formvalid=false;
          return;
      }
      if (this.myForm.valid) {
        this.formvalid=true;
      this._baseURL= 'Welcome'+" "+ this.myForm.controls.username.value;
    }
    this.user=this.myForm.controls.username.value;
    this.pwd=this.myForm.controls.password.value;
  }
  rest(){
    this.myForm.reset();
    this.submitted = false;
  }
  }
  </code></pre>
  
  <p>my login component html is:</p>
  
  <pre><code>        &lt;h1 class="text-center" [hidden]="formvalid"&gt;Login&lt;/h1&gt;
            &lt;form [formGroup]="myForm" (ngSubmit)="Submitme()" class="text-center"&gt;
             &lt;div class="container bg-dark" [hidden]="formvalid" style="border: 1px solid black;"&gt;
           &lt;div class="row mt-3"&gt;
             &lt;div class="col-lg-5"&gt;
           &lt;label for="name" class="text-white"&gt;Username :&lt;/label&gt;
           &lt;/div&gt;
           &lt;input type="text" formControlName="username" class="col-lg-4 form-control"
             [ngClass]="{ 'is-invalid': submitted &amp;amp;&amp;amp; myForm.controls.username.errors }"&gt;
            &lt;div *ngIf="submitted &amp;amp;&amp;amp; myForm.controls.username.errors" class="text-danger"&gt;
              &lt;div *ngIf="myForm.controls.username.errors.required"&gt;First Name is required&lt;/div&gt;
          &lt;/div&gt;
         &lt;/div&gt;
       &lt;div class="row mt-2"&gt;
             &lt;div class="col-lg-5"&gt;
         &lt;label for="pwd" class="text-white"&gt;Password :&lt;/label&gt;
           &lt;/div&gt;
        &lt;input type="password" formControlName="password" class="col-lg-4 form-control"
        [ngClass]="{ 'is-invalid': submitted &amp;amp;&amp;amp; myForm.controls.password.errors }"&gt;
         &lt;div *ngIf="submitted &amp;amp;&amp;amp; myForm.controls.password.errors" class="text-danger"&gt;
       &lt;div *ngIf="myForm.controls.password.errors.required"&gt;password is required&lt;/div&gt;
        &lt;div *ngIf="myForm.controls.password.errors.pattern"&gt;Pwd must contain atleast one upper and 
      lower case character one special character one digit and 8 characters in length  &lt;/div&gt;
     &lt;/div&gt;
      &lt;/div&gt;
       &lt;button class="btn btn-primary mt-2 mb-3" type="submit" 
     [routerLink]="'/afterlog'"&gt;Submit&lt;/button&gt;&amp;nbsp;
       &lt;input type="button" (click)="rest()" value="Reset" class="btn btn-primary mt-2 mb-3"&gt;
   &lt;/div&gt;
        &lt;/form&gt;
  </code></pre>
  
  <p>After login i want to redirect to another component with welcome message using routing in angular 8:
  Thanks in advance!!!!</p>