Get active route data inside router.events

How to get active route data such as params inside a signed router.events?

I want to not subscribe to this.route.params!

// Catch any events in a certain component, where I subscribe to it!
this.router.events.subscribe(event =>
{ 
// The event object has only the url (when is NavigationStart/End), there is nothing useful for me


});

UPDATE

My question is different because I am not asking how to respond to router events!

I ask how to get route activation parameters in a .events router!

That's for sure!

+4
source share
2 answers
this.router.events.subscribe(event =>
{ 
  console.log(this.router.routerState.root);
  console.log(this.router.routerState.root.firstChild);
  console.log(this.router.routerState.root.firstChild && this.router.routerState.root.firstChild.firstChild);
});
0
source

Try the following:

import { ActivatedRoute } from '@angular/router';

@Component({
    ...
})
export class TestComponent implements OnInit{
    constructor(protected route: ActivatedRoute) {}
    ngOnInit() {
        let name = this.route.snapshot.params['name'];
    }
}

This introduces the current active route, and the latter you can get information from this route.

+3
source

Source: https://habr.com/ru/post/1665939/


All Articles