这是我的app-routing.module.ts:
const appRoutes: Routes = [
{path: '', component: MainComponent, children:[
{path: '', component: AppComponent, children:[
{path: 'home', component: HomeComponent},
{path: 'register', component: RegisterComponent},
{path: 'login', component: LoginComponent},
]},
{path: 'patient', component: PatientComponent, children: [
{ path: 'patient/profile', component: PatientProfileComponent, outlet: 'patient-outl'},
{ path: 'patient/changepass', component: ChangePasswordComponent, outlet: 'patient-outl'}
],
canActivate: [RoleGuard],
data: { roles: ['PATIENT'] }
},
{path: 'admin', component: AdminComponent, canActivate: [RoleGuard], data: { roles: ['ADMIN'] }},
{path: 'dentist', component: DentistComponent, canActivate: [RoleGuard], data: { roles: ['DENTIST'] }},
{path: '**', component: HomeComponent}
]}
];
我从患者组件中的点击导航到如下更改通道:
<a routerLink="/patient/changepass" routerLinkActive="active">Change Password</a>
但实际打开的是HomeComponent而不是ChangePasswordComponent。网址是正确的 - / patient / changepass,但加载的组件是错误的..任何想法为什么会这样?
编辑:
我也试着像这样导航:
<a (click)="editProfile()">Edit Profile</a>
和
editProfile(){
this.router.navigate(['/patient/profile']);
}
但结果相同 - 导航到主页组件..
答案 0 :(得分:0)