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

  ...
}

相关内容

热门资讯

透视推荐"wepok... 透视推荐"wepoker开脚本视频"一贯有辅助脚本(哔哩哔哩)1、下载好wepoker开脚本视频透视...
透视曝光"wepok... 透视曝光"wepoker私人局俱乐部"都是是有辅助教程(哔哩哔哩)1、下载好wepoker私人局俱乐...
透视辅助"wepok... 透视辅助"wepoker有人用过吗"其实是有辅助神器(哔哩哔哩)1、上手简单,内置详细流程视频教学,...
透视推荐"we po... 透视推荐"we poker辅助器v3.3"总是有辅助软件(哔哩哔哩)1、下载好we poker辅助器...
透视有挂"we-po... 透视有挂"we-poker是什么软件"果然有辅助方法(哔哩哔哩)1、we-poker是什么软件透视辅...
透视详细"poker... 透视详细"poker world辅助器"原来有辅助攻略(哔哩哔哩)1、游戏颠覆性的策略玩法,独创攻略...
透视分享"aapok... 透视分享"aapoker怎么拿好牌"总是有辅助神器(哔哩哔哩)1、每一步都需要思考,不同水平的挑战a...
透视有挂"hhpok... 透视有挂"hhpoker德州牛仔视频"都是真的是有辅助软件(哔哩哔哩)1、实时hhpoker德州牛仔...
透视关于"线上德州的... 透视关于"线上德州的辅助器是什么"原来有辅助插件(哔哩哔哩)1、每一步都需要思考,不同水平的挑战线上...
透视推荐"德扑之心免... 透视推荐"德扑之心免费透视"其实是真的辅助技巧(哔哩哔哩)德扑之心免费透视辅助器是一种具有地方特色的...