Modify data object in ActivatedRoute

后端 未结 3 1456
無奈伤痛
無奈伤痛 2020-12-19 22:04

I need to modify the breadcrumb value in the data object of my current route. Here is my route configuration.

      {
    path: \"users\",
    component: Us         


        
3条回答
  •  执笔经年
    2020-12-19 22:32

    I assume you want to modify the data before the navigation starts. Because it is not clear from the question.

    Look for NavigationStart event and set this._route.snapshot.data instead of this._route.data.

    this.router.events
    .filter(event => event instanceof NavigationStart)
    .subscribe(() => {
         this._route.snapshot.data = { breadcrumb: this.user.displayName };
    });
    

提交回复
热议问题