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

  ...
}

相关内容

热门资讯

透视好牌!xpoker怎么作必... 透视好牌!xpoker怎么作必弊(透视)原来真的有辅助app(证实有挂)-哔哩哔哩xpoker怎么作...
目前!德普之星透视(透视)真是... 目前!德普之星透视(透视)真是存在有辅助软件(有挂方法)-哔哩哔哩1、玩家可以在德普之星透视透视最简...
透视挂透视!fishpoker... 透视挂透视!fishpoker透视底牌(透视)好像有辅助插件(有挂透视)-哔哩哔哩1.fishpok...
连日来!werplan辅助软件... 连日来!werplan辅助软件(透视)一贯有辅助插件(存在有挂)-哔哩哔哩1、玩家可以在werpla...
透视规律!pokemmo辅助脚... 透视规律!pokemmo辅助脚本(透视)竟然真的有辅助神器(有挂分享)-哔哩哔哩1、起透看视 pok...
透视好友房!wpk免费辅助(透... 透视好友房!wpk免费辅助(透视)确实真的是有辅助平台(新版有挂)-哔哩哔哩wpk免费辅助脚本下载中...
透视辅助!哈糖大菠萝有没有挂(... 透视辅助!哈糖大菠萝有没有挂(透视)一贯是真的辅助插件(的确有挂)-哔哩哔哩1、全新机制【哈糖大菠萝...
透视智能ai!pokemmo内... 透视智能ai!pokemmo内置修改器(透视)确实有辅助下载(有挂技巧)-哔哩哔哩1、许多玩家不知道...
透视实锤!wejoker辅助脚... 透视实锤!wejoker辅助脚本(透视)都是存在有辅助软件(有挂分析)-哔哩哔哩1、玩家可以在wej...
透视讲解!wepoker辅助器... 透视讲解!wepoker辅助器下载(透视)果然有辅助app(有挂功能)-哔哩哔哩wepoker辅助器...