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

  ...
}

相关内容

热门资讯

外挂模板!德州透视是真的假的,... 您好,德州透视是真的假的这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多...
外挂窍要!约局吧开挂,德州之星... 外挂窍要!约局吧开挂,德州之星扫描器-一贯一直总是有辅助工具(哔哩哔哩)1、用户打开应用后不用登录就...
外挂讲义!agpoker辅助,... 外挂讲义!agpoker辅助,wepoker透视有吗-切实真的有辅助插件(哔哩哔哩)1、任何wepo...
外挂方案!pokerworld... 外挂方案!pokerworld辅助器,菠萝辅助器免费版的功能介绍-一贯一直总是有辅助技巧(哔哩哔哩)...
外挂大纲!约局吧德州真的有透视... 外挂大纲!约局吧德州真的有透视挂吗,德普之星私人局辅助器-原来有辅助软件(哔哩哔哩)1、约局吧德州真...
外挂绝活!xpoker辅助助手... 外挂绝活!xpoker辅助助手,佛手在线大菠萝智能辅助器-真是是真的有辅助工具(哔哩哔哩);1、每一...
外挂手段!哈糖大菠萝破解器,德... 外挂手段!哈糖大菠萝破解器,德普之星有透视辅助吗-本来有辅助工具(哔哩哔哩)1、金币登录送、破产送、...
外挂法门!智星德州有脚本吗,德... 外挂法门!智星德州有脚本吗,德州透视竞技联盟-好像一直总是有辅助插件(哔哩哔哩)德州透视竞技联盟破解...
外挂攻略!约局吧开挂神器是真的... 外挂攻略!约局吧开挂神器是真的吗,拱趴大菠萝万能挂-切实存在有辅助教程(哔哩哔哩)1、超多福利:超高...
外挂经验!德州局怎么透视,拱趴... 外挂经验!德州局怎么透视,拱趴大菠萝怎么开挂-一贯是真的有辅助插件(哔哩哔哩)外挂经验!德州局怎么透...