angular - Know in parent what child RouteSegment is selected? -


i able find out in parent component, or app component, child route active. instance able style active route link. see [routelink] adds 'router-link-active' class, in example have 'home' route '/' has class no matter route use. there way see in parent of outlet route on?

i've injected location @angular/common , able see full path guess looking @ when route changes:

ngoninit() {   this.router.changes.subscribe(changes => {     console.log('location info:', this.location.platformstrategy.path());   }); } 

is there way @ routetree or active routesegment parent? or check router-outlet , see component loaded it?

you can access current route like

  constructor(private router:router, private routeserializer:routerurlserializer, private location:location) {     router.changes.first().subscribe(() => {        console.log('router', this.router);       let urltree = this.routeserializer.parse(location.path());        // individual segments of route use       console.log('serializer', urltree.children(urltree.root)[0].segment);       console.log('serializer', urltree.children(urltree.children(urltree.root)[0])[0].segment);     });   } 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -