AngularM AngularM - 1 year ago 112
Javascript Question

Angular 2.0 - How to detect route change?

Angular 2.0 - How to detect route change?

I looking to detect route change in my App.ts file.

Once I've done this I will check the global user token to see if they are logged in. Then I can redirect the user if they are not logged in.

Thank you in advance!

Answer Source

In Angular 2 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*/)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download