【问题标题】:Use *ngIf= for specific router link and all child routes将 *ngIf= 用于特定路由器链接和所有子路由
【发布时间】:2020-11-27 15:51:04
【问题描述】:

问题:在父路由的所有子路由中显示[内容],即。 <div *ngIf="router.url === '/parent/child'">[content]</div> 使 ./parent/child1、./parent/child2、./parent/child(n) 都显示 [content]

建议的解决方案: <div *ngIf="router.url === '/parent/**'">[content]</div> 或变体 <div *ngIf="router.url === '/parent/..'">[content]</div>,似乎不被 angular 框架接受。

文档:https://angular.io/guide/router#setting-up-wildcard-routes

基于

【问题讨论】:

  • 你试过
    [content]
  • 完美解决方案。谢谢。

标签: angular routes wildcard router


【解决方案1】:

将 Fiehra 的回答作为建议的解决方案:使用 *ngIf="router.url.includes('/parent/) 来划分引用父级的子路由。解决了我的问题。

See more here

编辑:您还可以设置自定义服务以确保您位于适当类型的页面上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-06
    • 2018-03-24
    • 2013-09-12
    • 2021-04-03
    • 2021-12-04
    • 2022-06-15
    • 2023-04-09
    相关资源
    最近更新 更多