AngularSideNav无法根据路由更新内容
创始人
2024-10-29 15:31:37
0

要更新Angular SideNav中的内容,需要通过Angular路由守卫进行操作。以下是解决该问题的代码示例:

在ngOnInit中注册路由守卫:

export class MyComponent implements OnInit, OnDestroy {
  private routerEventsSubscription!: Subscription;

  constructor(private router: Router) {}

  ngOnInit() {
    this.routerEventsSubscription = this.router.events.subscribe(event => {
      if (event instanceof NavigationStart) {
        // Update SideNav content
      }          
    });
  }

  ngOnDestroy() {
    this.routerEventsSubscription.unsubscribe();
  }
}

在路由守卫中更新SideNav内容:

export class MyComponent implements OnInit, OnDestroy {
  ...

  ngOnInit() {
    ...

    this.routerEventsSubscription = this.router.events.subscribe(event => {
      if (event instanceof NavigationStart) {
        const route = this.router.config.find(r => r.path === this.router.url);
        // Update SideNav content based on the current route
      }          
    });
  }

  ...
}

相关内容

热门资讯

透视系统!wepoker辅助软... 您好,wepoker辅助软件价格这款游戏可以开挂的,确实是有挂的,需要了解加去威信【48527505...
目前!wepoker怎么设置盖... 目前!wepoker怎么设置盖牌(透视)好像真的是有辅助工具(真是有挂)-哔哩哔哩1、许多玩家不知道...
透视中牌率!hhpoker辅助... 透视中牌率!hhpoker辅助器(透视)本来存在有辅助插件(有挂存在)-哔哩哔哩一、hhpoker辅...
现有关情况通报如下!德扑HHp... 现有关情况通报如下!德扑HHpoker有挂吗(透视)都是有辅助安装(有挂解密)-哔哩哔哩1、超多福利...
今年以来!hhpoker的辅助... 今年以来!hhpoker的辅助是真的吗(透视)切实有辅助平台(有挂教学)-哔哩哔哩1、起透看视 hh...
随着!菠萝德州透视脚本(透视)... 随着!菠萝德州透视脚本(透视)确实有辅助插件(有挂方针)-哔哩哔哩1、超多福利:超高返利,海量正版游...
透视好牌!wepoker免费辅... 透视好牌!wepoker免费辅助器(透视)一直是有辅助辅助器(有挂细节)-哔哩哔哩1.wepoker...
透视模拟器!wepoker私人... 透视模拟器!wepoker私人局俱乐部怎么进(透视)真是真的有辅助神器(有挂教学)-哔哩哔哩小薇(辅...
为切实保障!hhpoker有没... 为切实保障!hhpoker有没有外开挂(透视)一直是有辅助平台(有挂头条)-哔哩哔哩1、很好的工具软...
透视插件!wepoker透视破... 透视插件!wepoker透视破解版(透视)好像是有辅助修改器(有挂猫腻)-哔哩哔哩1、在wepoke...