特别是一个routerlink在角度7中不起作用

时间:2019-02-13 09:49:36

标签: angular routing angular-material angular-routing angular7

我正在使用带有材质框架的angular 7。我正在通过路由器处理菜单,实际上它正在工作,但是一个链接没有注册。我确实在模块和路由中添加了它。我在下面附加了渲染的DOM: enter image description here

这是我的AppComponent.ts内容

<mat-nav-list class="sidenav-submenu" *ngIf="showMenu">
  <a mat-list-item routerLink="/BlockMaster"><fa name="building"></fa>&nbsp;&nbsp;Block Master</a>
  <a mat-list-item routerLink="/FloorMaster"><fa name="building"></fa>&nbsp;&nbsp;Floor Master</a>
  <a mat-list-item routerLink="/CellMaster"><fa name="lock"></fa>&nbsp;&nbsp;Cell Master</a>
  <a mat-list-item routerlink="/LocatorMaster"><fa name="location-arrow"></fa>&nbsp;&nbsp;Locator Master</a>
  <a mat-list-item routerLink="/TagMaster"><fa name="tags"></fa>&nbsp;&nbsp;Tag Master</a>
  <a mat-list-item routerLink="/TagMember"><fa name="users"></fa>&nbsp;&nbsp;Member Master</a>
  <a mat-list-item routerLink="/VisitorConfRoom"><fa name="street-view"></fa>&nbsp;&nbsp;Visitor Conf Room Master</a>
  <a mat-list-item routerLink="/PrisonerConfRoom"><fa name="university"></fa>&nbsp;&nbsp;Prisoner Conf Room Master</a>
  <a mat-list-item routerLink="/MapLocator"><fa name="university"></fa>&nbsp;&nbsp;Map Locator</a>
  <a mat-list-item routerLink="/TagTracker"><fa name="university"></fa>&nbsp;&nbsp;Tag Tracker</a>
</mat-nav-list>

我的路由配置如下:

 Routes = [
{ path: '', component: HomeComponent, canActivate: [AuthGuard] },
{ path: 'CellMaster', component: CellMasterComponent, canActivate: [AuthGuard] },
{ path: 'TagMaster', component: TagMasterComponent, canActivate: [AuthGuard] },
{ path: 'TagMember', component: TagMemberComponent, canActivate: [AuthGuard] },
{ path: 'LocatorMaster', component: LocatorMasterComponent, canActivate: [AuthGuard] },
{ path: 'BlockMaster', component: BlockMasterComponent, canActivate: [AuthGuard] },
{ path: 'FloorMaster', component: FloorMasterComponent, canActivate: [AuthGuard] },
{ path: 'VisitorConfRoom', component: VisitorConfRoomMasterComponent, canActivate: [AuthGuard] },
{ path: 'PrisonerConfRoom', component: PrisonerConfRoomMasterComponent, canActivate: [AuthGuard] },
{ path: 'MapLocator', component: MapLocatorComponent, canActivate: [AuthGuard] },
{ path: 'TagTracker', component: TagTrackerComponent, canActivate: [AuthGuard] }];

我不确定是什么问题。

2 个答案:

答案 0 :(得分:0)

尝试将routerLinkActive="active"添加到您的标签

示例:

<a mat-list-item routerLink="/BlockMaster" routerLinkActive="active">
    <fa name="building"></fa>&nbsp;&nbsp;Block Master
</a>

答案 1 :(得分:0)

您写错了。 router[l]ink="/LocatorMaster" => router[L]ink="/LocatorMaster"