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辅助工具,安装教程(有挂神器)(UU poke...
玩家必备教程!wejoker黑... 玩家必备教程!wejoker黑侠辅助器,pokemmo手机版脚本,切实教程(有挂神器);人气非常高,...
实操分享!cloudpoker... 自定义cloudpoker怎么开挂系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用...
总算清楚!pokemmo脚本辅... 总算清楚!pokemmo脚本辅助下载,hhpoker软件安装包,可靠教程(有挂方法)1、许多玩家不知...
最新技巧!wepoker底牌透... 最新技巧!wepoker底牌透视,wejoker内置辅助,AI教程(有挂透视)1、点击下载安装,微扑...
技巧知识分享!wejoker透... 技巧知识分享!wejoker透视方法,hhpoker辅助软件是真的么,微扑克教程(有挂辅助);hhp...
科普常识!We poker辅助... 科普常识!We poker辅助器下载,hhpoker作弊码,wpk教程(有挂神器);原来确实真的有挂...
实操分享!wepoker私人辅... 实操分享!wepoker私人辅助器,哈糖大菠萝有挂吗,插件教程(有挂神器)是一款可以让一直输的玩家,...
总算了解!xpoker辅助,a... 总算了解!xpoker辅助,aapoker辅助插件工具,扑克教程(有挂软件);致您一封信;亲爱aap...
重磅来袭!wepoker破解器... 重磅来袭!wepoker破解器有用吗,wepoker辅助器官方,安装教程(有挂教程);最新版2024...