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

  ...
}

相关内容

热门资讯

专业透视!werplan透视挂... 专业透视!werplan透视挂!一贯真的有辅助攻略(有挂总结)-哔哩哔哩werplan透视挂脚本下载...
揭露透视!wpk透视工作室,w... 揭露透视!wpk透视工作室,wpk俱乐部怎么作必弊,举措教程(有挂秘笈)-哔哩哔哩1、游戏颠覆性的策...
必备透视!佛手在线是不是有挂!... 必备透视!佛手在线是不是有挂!确实是有辅助工具(有挂秘笈)-哔哩哔哩;1、玩家可以在佛手在线是不是有...
揭幕透视!wepoker免费透... 揭幕透视!wepoker免费透视脚本,wepoker黑侠辅助器正版下载,讲义教程(有挂技巧)-哔哩哔...
科普透视!佛手大菠萝有挂吗!切... 科普透视!佛手大菠萝有挂吗!切实一直总是有辅助app(有挂秘籍)-哔哩哔哩1、实时佛手大菠萝有挂吗透...
科普透视!wejoker辅助器... 科普透视!wejoker辅助器怎么卖,hhpoker透视脚本下载,妙计教程(有人有挂)-哔哩哔哩1、...
曝光透视!拱趴大菠萝机器人!原... 曝光透视!拱趴大菠萝机器人!原来存在有辅助工具(有挂教学)-哔哩哔哩1)拱趴大菠萝机器人有没有挂:进...
详情透视!poker worl... 详情透视!poker world辅助,模拟器打开hhpoker,总结教程(有挂技术)-哔哩哔哩1、不...
分享透视!智星菠萝辅助!原来是... 分享透视!智星菠萝辅助!原来是有辅助脚本(揭秘有挂)-哔哩哔哩1、任何智星菠萝辅助透视是真的假的的玩...
解谜透视!约局吧德州真的有透视... 解谜透视!约局吧德州真的有透视挂吗,wepoker辅助器有哪些功能,手段教程(有挂教学)-哔哩哔哩1...