In the new router ( > = RC.0 ) in AppComponent this can be done with
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); }); }
(to get the second segment)
In MyComponent this is simpler:
routerOnActivate(curr:RouteSegment, prev?:RouteSegment, currTree?:RouteTree, prevTree?:RouteTree):void { this.id = curr.getParam('id'); }
Günter zöchbauer
source share