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

  ...
}

相关内容

热门资讯

透视科普"xpoke... 透视科普"xpoker辅助器"都是是有辅助工具(哔哩哔哩)1、玩家可以在xpoker辅助器透视最简单...
透视专业"wepok... 透视专业"wepoker辅助软件视频"一直是有辅助软件(哔哩哔哩)透视专业"wepoker辅助软件视...
透视了解"约局吧德州... 透视了解"约局吧德州真的存在透视吗"确实是有辅助挂(哔哩哔哩)1、实时约局吧德州真的存在透视吗透视辅...
透视教你"pokem... 透视教你"pokemmo脚本手机版"原来是真的辅助脚本(哔哩哔哩)1、用户打开应用后不用登录就可以直...
透视推荐"wepok... 透视推荐"wepoker插件下载"真是有辅助脚本(哔哩哔哩)运wepoker插件下载辅助工具,进入游...
透视解迷"wepok... 透视解迷"wepoker能不能透视"本来存在有辅助插件(哔哩哔哩)1、任何wepoker能不能透视透...
透视专业"wepok... 透视专业"wepoker私人辅助器"都是是有辅助app(哔哩哔哩);1、打开软件启动之后找到中间准星...
透视解迷"we-po... 透视解迷"we-poker辅助"总是有辅助攻略(哔哩哔哩)在进入we-poker辅助软件靠谱后,参与...
透视有挂"we-po... 透视有挂"we-poker辅助器"原来有辅助插件(哔哩哔哩)1、该软件可以轻松地帮助玩家将we-po...
透视必备"xpoke... 透视必备"xpoker辅助怎么用"其实真的有辅助攻略(哔哩哔哩)xpoker辅助怎么用透视方法中分为...