Q:

Angular CLI refresh content on change route

I have an Angular CLI app. 
In the app I have a map (on the right side) and left panel (which shows current information about route). If I click on map, the openlayers find the nearest feature, and redirects me to /map/routeID/detail. Everything works like charm (on the TS of detail component I load the data from API and everything if fine).
The problem is... If I click to another place (near some other route) the URL changes (so I've been redirected to another route detail). But the informations are old (from the other route). I'm doing loading in NgOnInit, I tried to print console string and I found out the NgOnInit is not called when my route changes from fox example /map/1/detail to /map/2/detail.
How can I handle this? For example If the route changes, the NgOnInit is triggered again or something like this.

A:

I believe you want to watch for changes to the route parameters instead of just getting the initial value as in your comment. To do this you will need to subscribe to one of the observables (e.g. paramMap https://angular.io/api/router/ParamMap) on the ActivatedRoute object and then run the code that is needed on every route change.
@Component({...})
class ExampleComponent {
    constructor(private route: ActivatedRoute) {
    }

    ngOnInit() {
        this.route.paramMap.subscribe(map => {
            // run code to process
        });
    }
}

As a note, the paramMap subscription does not need to be unsubscribed from according to the docs (it is automatically unsubscribed for you).

