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

  ...
}

相关内容

热门资讯

透视插件!线上德州的辅助器是什... 透视插件!线上德州的辅助器是什么(透视)安装教程(2020已更新)(哔哩哔哩)1、游戏颠覆性的策略玩...
透视代打!aapoker破解侠... 透视代打!aapoker破解侠是真的吗(透视)真的假的(总是真的是有挂)1、该软件可以轻松地帮助玩家...
透视安装!菠萝德普辅助器免费版... 透视安装!菠萝德普辅助器免费版在哪里(透视)高科技教程(2026已更新)(哔哩哔哩)1、任何菠萝德普...
透视辅助!aapoker透视脚... 透视辅助!aapoker透视脚本(透视)万能辅助器(原来真的是有挂)1、很好的工具软件,可以解锁游戏...
透视中牌率!poker mas... 透视中牌率!poker master辅助(透视)介绍教程(2021已更新)(哔哩哔哩)在进入poke...
透视肯定!aapoker能控制... 透视肯定!aapoker能控制牌吗(透视)透视脚本(本来真的是有挂)1、让任何用户在无需aapoke...
透视教程!德州私人局怎么透视(... 透视教程!德州私人局怎么透视(透视)教你教程(2021已更新)(哔哩哔哩)1、构建自己的德州私人局怎...
透视代打!aapoker发牌逻... 透视代打!aapoker发牌逻辑(透视)发牌逻辑(确实是有挂)1、进入到aapoker发牌逻辑黑科技...
透视好牌!pokermaste... 透视好牌!pokermaster破解版(透视)插件教程(2020已更新)(哔哩哔哩)1、pokerm...
透视工具!aapoker发牌逻... 透视工具!aapoker发牌逻辑(透视)辅助插件工具(其实有挂)1、超多福利:超高返利,海量正版游戏...