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俱乐部有没有辅助,如何判断wpk辅助软件的真假,本来是真的有辅助攻略(哔哩哔哩)1、...
解迷透视!htx矩阵wepok... 解迷透视!htx矩阵wepoker辅助,wepoker有没有挂,其实一直都是有辅助脚本(哔哩哔哩)1...
专业透视!wpk插件,wpk俱... 专业透视!wpk插件,wpk俱乐部辅助器,一贯有辅助攻略(哔哩哔哩)1. 选牌创建新账号,点击进入游...
有挂透视!wpk软件是正规的吗... 有挂透视!wpk软件是正规的吗,有哪些免费的wpk作比弊码,原来存在有辅助软件(哔哩哔哩)小薇(辅助...
普及透视!德普之星有辅助软件吗... 普及透视!德普之星有辅助软件吗,德普之星透视辅助软件是真的吗,竟然存在有辅助工具(哔哩哔哩)1、首先...
透视透视!德扑圈透视,德普之星... 透视透视!德扑圈透视,德普之星透视辅助插件,确实有辅助方法(哔哩哔哩)1、下载好正确养号方法之后点击...
揭幕透视!aapoker辅助软... 揭幕透视!aapoker辅助软件合法吗,aapoker万能辅助器,真是是有辅助方法(哔哩哔哩)破解侠...
辅助透视!wepoker软件安... 辅助透视!wepoker软件安装包,hhpoker怎么破解,好像真的有辅助软件(哔哩哔哩)1、模拟器...
普及透视!aapoker怎么控... 普及透视!aapoker怎么控制牌,aapoker俱乐部靠谱吗,总是一直总是有辅助脚本(哔哩哔哩)1...
开挂透视!德普之星私人局辅助免... 开挂透视!德普之星私人局辅助免费,德普之星怎么开辅助,其实真的是有辅助脚本(哔哩哔哩)1、进入游戏-...