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

  ...
}

相关内容

热门资讯

有挂透视!uupoker透视,... 有挂透视!uupoker透视,拱趴大菠萝机器人(透视)一直是真的有辅助软件(哔哩哔哩)1、拱趴大菠萝...
总结透视!cloudpoker... 总结透视!cloudpoker外开挂,约局吧辅助器(透视)本来是真的有辅助教程(哔哩哔哩)1、玩家可...
解谜透视!epoker免费透视... 解谜透视!epoker免费透视脚本,pokerworld软件(透视)本来一直总是有辅助方法(哔哩哔哩...
教你透视!epoker透视,哈... 教你透视!epoker透视,哈糖大菠萝开挂(透视)确实有辅助方法(哔哩哔哩)1、每一步都需要思考,不...
科普透视!pokemomo辅助... 科普透视!pokemomo辅助软件,哈糖大菠萝有挂吗(透视)都是真的有辅助工具(哔哩哔哩)1、下载好...
专业透视!拱趴大菠萝有挂吗,a... 专业透视!拱趴大菠萝有挂吗,aa poker辅助(透视)其实是有辅助软件(哔哩哔哩)拱趴大菠萝有挂吗...
开挂透视!哈糖大菠萝免费辅助器... 开挂透视!哈糖大菠萝免费辅助器,fishpoker透视(透视)一直真的有辅助脚本(哔哩哔哩)所有人都...
了解透视!智星菠萝辅助,德州来... 了解透视!智星菠萝辅助,德州来玩辅助器(透视)一贯一直都是有辅助攻略(哔哩哔哩)1、点击下载安装,德...
解谜透视!大菠萝789辅助器下... 解谜透视!大菠萝789辅助器下载,xpoker辅助怎么用(透视)其实存在有辅助技巧(哔哩哔哩)1、实...
曝光透视!哈糖大菠萝免费辅助器... 曝光透视!哈糖大菠萝免费辅助器,德州机器人代打脚本(透视)真是是真的有辅助脚本(哔哩哔哩);1、哈糖...