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

  ...
}

相关内容

热门资讯

最终!哈糖大菠萝怎么开挂(透视... 最终!哈糖大菠萝怎么开挂(透视)丽水都莱破解器(切实有辅助工具)-哔哩哔哩1、每一步都需要思考,不同...
透视攻略!竞技联盟破解版最新版... 透视攻略!竞技联盟破解版最新版(透视)pokemmo辅助脚本(辅助)本来是真的有脚本(哔哩哔哩)1、...
于此同时!wepoker透视辅... 于此同时!wepoker透视辅助下载(透视)玖游卡五星辅助(竟然是真的辅助工具)-哔哩哔哩1、下载好...
透视妙招!约局吧开挂(透视)哈... 透视妙招!约局吧开挂(透视)哈糖大菠萝开挂(辅助)总是真的有攻略(哔哩哔哩)1、让任何用户在无需哈糖...
透视科技!we-poker正规... 透视科技!we-poker正规吗(透视)微信小程序微乐辅助器教程(总是存在有辅助插件)-哔哩哔哩1、...
透视步骤!德州来玩辅助器(透视... 透视步骤!德州来玩辅助器(透视)pokemmo手机版脚本(辅助)原来真的有app(哔哩哔哩)1、po...
透视ai代打!如何下载德普之星... 透视ai代打!如何下载德普之星辅助软件(透视)微信小程序万能修改器(原来是真的辅助插件)-哔哩哔哩微...
透视模块!德州局透视脚本免费版... 透视模块!德州局透视脚本免费版下载手机版(透视)uupoker透视(辅助)一贯真的是有脚本(哔哩哔哩...
目前!wepoker私人局辅助... 目前!wepoker私人局辅助挂(透视)天酷大厅辅助(切实有辅助工具)-哔哩哔哩天酷大厅辅助是不是有...
透视攻略!来玩app破解(透视... 透视攻略!来玩app破解(透视)约局吧怎么看有没有挂(辅助)切实真的有神器(哔哩哔哩)1、玩家可以在...