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怎么挂底牌,wepoker买脚本靠谱吗-其实是真的有辅助工具(哔哩哔哩)1、...
透视了解!德普之星怎么设置埋牌... 透视了解!德普之星怎么设置埋牌,德普之星辅助器app-原来真的是有辅助神器(哔哩哔哩)1、免费脚本咨...
透视详情!aa poker透视... 透视详情!aa poker透视软件,aapoker ai插件-本来存在有辅助攻略(哔哩哔哩)能透视中...
透视专业!wepoker挂,w... 透视专业!wepoker挂,wepoker怎么设置透视-确实真的有辅助神器(哔哩哔哩)运辅助工具,进...
透视普及!wepoker怎么设... 透视普及!wepoker怎么设置盖牌,wepoker怎么下载游戏-一直一直都是有辅助软件(哔哩哔哩)...
透视曝光!wepoker免费脚... 透视曝光!wepoker免费脚本咨询,wepoker轻量版辅助-都是一直都是有辅助方法(哔哩哔哩)1...
透视解密!wepoker有透视... 透视解密!wepoker有透视功能吗,htx矩阵wepoker辅助-确实真的有辅助脚本(哔哩哔哩)1...
透视有挂!wpk辅助软件,wp... 透视有挂!wpk辅助软件,wpk透视辅助靠谱吗-一直真的有辅助教程(哔哩哔哩)1、玩家可以在线上大神...
透视分享!aapoker怎么控... 透视分享!aapoker怎么控制牌,aapoker ai插件-切实有辅助方法(哔哩哔哩)1、免费脚本...
透视解迷!werplan外挂,... 透视解迷!werplan外挂,智星菠萝辅助-真是真的是有辅助技巧(哔哩哔哩)1、很好的工具软件,可以...