0

I have a Angular 6 application , Im able to detect route change through angular logic, But i have a requirement to detect changes through Javascript or Jquery script, When ever there is a change in route we need to trigger a javascript function.

Please help me, Thank you in advance

A R S
  • 33
  • 2
  • 17

1 Answers1

-1

Here's how I was able to detect the URL change and trigger an event using Javascript in Angular7:

 var oldLocation= '';
  var newLocation= '';

setInterval(() => {
      init();
    }, 500);
init() {
    this.newLocation = window.location.pathname;
    if (oldLocation !== newLocation) {
      EventTrigger();
      oldLocation = newLocation;
    }
  }

  EventTrigger() {
    console.log(this.newLocation, this.oldLocation);
  }
Sundas Riasat
  • 187
  • 1
  • 9
  • Actually i need to trigger a event/function when ever there is a change in route, Your logic can be used with in the function to get the current route information – A R S Jan 29 '20 at 07:04