Angular2 Get router params outside of router-outlet

后端 未结 5 1421
不思量自难忘°
不思量自难忘° 2021-01-04 14:26

I have a dashboard application which consists of a treeview component (which lists various content nodes) and a dashboard-edit component which renders some editable content

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-04 14:39

    In the new router (>= RC.0 <=RC.2) this would be

      import 'rxjs/add/operator/first';
      ...
    
      constructor(private router:Router, private routeSerializer:RouterUrlSerializer, private location:Location) {
        router.changes.first().subscribe(() => {
    
        let urlTree = this.routeSerializer.parse(location.path());
          console.log('id', urlTree.children(urlTree.children(urlTree.root)[0])[0].segment);
        });
      }
    

    See also Angular 2 RC1: Get parameters from the initial URL used

提交回复
热议问题