[Fixed] How to route a component without displaying root component


enter image description here App-routing.module.ts

const routes: Routes = [
{path:'candidate', component: SearchbyNameComponent}];


<div class="Candidates">
  <table class="list" cellpading="0" cellspacing="0">
  <tr *ngFor="let data of candidate_data">
    <td>{{data.joining_date | date}}</td>
  <div class="list-group">
    <a [routerLink]="['/candidate']">Search by Name</a>
    <a href="#" class="list-group-item" >Search by Exp</a>
    <a href="#" class="list-group-item" >Delete</a>


while clicking on Search by Name hyperLink the URL is changing but the SearchByNameComponent is loading below the App.component.html content. How do i display only SearchbyNameComponent on click and not whole content ? target = _blank doesn’t help.


You should have another route: {path:'', component: CandidateListComponent}];
And within App.component.html keep only the <router-outlet></router-outlet> and remove the <app-candidatelist></app-candidatelist>.
If you had as you have above, when you click on Search by Name hyperLink, the candidateList would be first rendered and only then the component associated with this new route would be rendered on <router-outlet></router-outlet>.

Leave a Reply

(*) Required, Your email will not be published