How to detect a route change in Angular?

Technology CommunityCategory: AngularHow to detect a route change in Angular?
VietMX Staff asked 3 years ago

In Angular you can subscribe (Rx event) to a Router instance. So you can do things like:

class MyClass {
    constructor(private router: Router) {
        router.subscribe((val) => /*whatever*/ )
    }
}