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

  ...
}

相关内容

热门资讯

透视总结!wpk透视是真的吗,... 您好,wpk系统是否存在作必弊行为这款游戏可以开挂的,确实是有挂的,需要了解加去威信【4852750...
透视窍门!wpk德州局怎么透视... 透视窍门!wpk德州局怎么透视,德普之星的辅助工具介绍(透视)好像真的有挂(哔哩哔哩)1、德普之星的...
透视项目!wepoker开脚本... 透视项目!wepoker开脚本视频,拱趴大菠萝有什么挂(透视)竟然有挂(哔哩哔哩)1、不需要AI权限...
透视模板!约局吧德州有挂吗,x... 透视模板!约局吧德州有挂吗,xpoker怎么作必弊(透视)果然真的有透视挂(哔哩哔哩)1、约局吧德州...
透视总结!xpoker辅助,w... 透视总结!xpoker辅助,wepoker怎么挂飞机(透视)一直存在有挂(哔哩哔哩)1、wepoke...
透视绝活儿!德州局透视,拱趴大... 透视绝活儿!德州局透视,拱趴大菠萝挂(透视)总是真的有透视软件(哔哩哔哩)1、完成拱趴大菠萝挂辅助器...
透视技法!wpk插件,hhpo... 透视技法!wpk插件,hhpoker脚本下载(透视)原来真的是有挂(哔哩哔哩)小薇(辅助器软件下载)...
透视模块!aapoker辅助怎... 透视模块!aapoker辅助怎么用,aapoker破解侠是真的吗(透视)本来存在有透视脚本(哔哩哔哩...
透视指南书!hh poker软... 透视指南书!hh poker软件,wepoker底牌透视(透视)果然存在有挂(哔哩哔哩)1、wepo...
透视方针!wpk有作必弊吗,w... 透视方针!wpk有作必弊吗,wpk插件辅助(透视)确实真的是有透视技巧(哔哩哔哩)1、该软件可以轻松...