title: Routing displays content of previous page too
body: <p>I am building a web-page which starts with a simple login box which contains username,password with input boxes and two buttons with name login and register.</p>
  
  <p>After clicking on the login button my page should route to another component which contains a navigation bar. It does route, no problem there. But the login box doesn't disappears after routing.</p>
  
  <p>So after routing, navigation bar appears but the login box is still there.</p>
  
  <p><strong>APP.COMPONENT.HTML</strong></p>
  
  <pre><code>      &lt;div class="background-image"&gt;
  
            &lt;router-outlet&gt;&lt;/router-outlet&gt;
           &lt;div class="content2"&gt;
  
            &lt;h2 &gt;Login&lt;/h2&gt;
           &lt;br&gt;
  
          &lt;form&gt;
         &lt;div class="form-group"&gt;
                &lt;label style="margin: 5px"&gt;Username&lt;/label&gt;
  
             &lt;input type="text"  /&gt;
  
             &lt;/div&gt;
              &lt;div class="form-group"&gt;
               &lt;label style="margin: 7.5px"&gt;Password&lt;/label&gt;
  
               &lt;input type="password" /&gt;
  
           &lt;/div&gt;
             &lt;div class="form-group"&gt;
         &lt;button (click)="onclick()" [disabled]="loading" class="btn btn- 
          primary"&gt;Login&lt;/button&gt;
        &lt;a href="/register" class="btn btn-link"&gt;Register&lt;/a&gt;
              &lt;/div&gt;
            &lt;/form&gt;
        &lt;/div&gt;
           &lt;/div&gt;
  </code></pre>
  
  <p><strong>APP.COMPONENT.TS</strong></p>
  
  <pre><code>import { Component } from '@angular/core';
  import { Router } from '@angular/router';
  
  @Component({
         selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.css']
             })
     export class AppComponent {
         title = 'welfareUI';
         constructor(private router: Router){
  
           }
        onclick()
        {
            this.router.navigateByUrl('/navbar');
        }
  
       }
  </code></pre>