代码之家  ›  专栏  ›  技术社区  ›  SatAj

如何防止父路由链接覆盖子路由链接

  •  3
  • SatAj  · 技术社区  · 9 年前

    我的示例中有嵌套导航(路线)

    <ul>
        <li *ngFor="let route of routes" [routerLink]="route.link" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">
            {{route.name}}</span>
            <!-- Secondary navigation (if exists) -->
            <ul *ngIf="route.children" class="secondary">
              <li *ngFor="let item of route.children" [routerLink]="item.link" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">
                {{item.name}}
              </li>
            </ul>
        </li>
    </ul>
    

    在这种嵌套情况下,我如何防止父路由器链接? 感谢你的帮助。

    1 回复  |  直到 9 年前
        1
  •  3
  •   John Montgomery    9 年前

    添加 (click)="$event.stopPropagation()" (click)="someFunction($event)" 然后打电话 stopPropagation() 如果需要在单击时运行其他逻辑,也可以在函数内部)到子元素,以防止其冒泡。

    推荐文章