I'm writing an application which create his content from data sent by a REST API. So I use only the route '**' in my app-routing module and parse the path given to request data to display.

But When i go on one of my component which is a button, it redirect me on a new page just like http://domain/newpage, and a settimeout loop will request data on my API to update data each X seconds.

But the problem come when I go back on the previous page (http://domain/), it didn't reload the whole page, and the settimeout of my newpage is always running in the back to update data that I don't want anymore. I tried to use this to disable the settimeout when I go on the previous page:

location.onPopState(() => {
  console.log('OnPopStage loaded')
  if (this.reloader != undefined) {
    console.log('unset reloader loaded')
    clearTimeout(this.reloader);
  }
});

(this.reloader contain the settimeout)

And it works, but when i go back on the page, it will reactivate my components and load new, so i will double the request each time i go again on the page.

Thanks in advance for your help.

0 Answers