I have the code in App Routing Module as follows.
const routes: Routes = [
{ path: '', redirectTo:'Person/AllPersons', pathMatch:'full' },
{ path: 'Person/AllPersons', component: AllPersonsComponent },
{ path: 'Person/AddPerson', component: AddPersonComponent },
{ path: 'Teacher/AllTeachers', component: AllTeachersComponent },
{ path: 'Teacher/AddTeacher', component: AddTeacherComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
Now in AllPersonsComponent.html I have the following code.
<a routerLink="Teacher/AddTeacher">Add Teacher</a>
Now when I click on it. It's not redirecting to AddTeacher Component. Instead it is populating an error as follows Cannot match any routes. URL Segment: 'Person/AllPersons/Teacher/AddTeacher'.
But when I do like this it is redirecting to Correct path.
<a (click)="Func()">Add Teacher</a>
And in .ts file as follows.
Func() {
this.router.navigate(['Teacher/AddTeacher']);
}
Then it is navigating to Add Teacher component. Can any one help me with this as of why routerLink is failing and how to achieve it through routerLink?