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
      }          
    });
  }

  ...
}

相关内容

热门资讯

此事备受玩家关注!wepoke... 此事备受玩家关注!wepoker模拟器哪个,兴动互娱辅助设置步骤详解,果然是真的有辅助技巧(哔哩哔哩...
随着!cloudpoker作必... 您好,土豪联盟辅助软件下载这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很...
此事引发网友热议!pokemm... 此事引发网友热议!pokemmo脚本辅助器下载,雀神麻将辅助透视,都是真的有辅助软件(哔哩哔哩)1)...
日前!hhpoker有没有作必... 日前!hhpoker有没有作必弊辅助,天天爱游戏辅助,原来真的有辅助方法(哔哩哔哩)1、游戏颠覆性的...
据文件显示!德州私人局脚本,亿... 据文件显示!德州私人局脚本,亿游十三道脚本插件,果然有辅助教程(哔哩哔哩)在进入亿游十三道脚本插件软...
出现新变化!wepoker私人... 出现新变化!wepoker私人局可以透视,天天爱游戏辅助,一直有辅助神器(哔哩哔哩)1、天天爱游戏辅...
在玩家背景下!hh poker... 在玩家背景下!hh poker插件下载,创思维激k辅助器,其实真的有辅助技巧(哔哩哔哩)创思维激k辅...
推出新举措!wepoker轻量... 推出新举措!wepoker轻量版辅助,星悦广东游戏辅助软件,确实真的是有辅助攻略(哔哩哔哩)1)星悦...
备受关注的!wpk真吗,蜀山四... 备受关注的!wpk真吗,蜀山四川小程序破解版下载,都是存在有辅助技巧(哔哩哔哩)1、蜀山四川小程序破...
目前来看!pokemmo脚本,... 目前来看!pokemmo脚本,福建天天开心攻略,一贯是真的有辅助技巧(哔哩哔哩)1、下载好福建天天开...