1

i am working on an angular 8 project , everything work's fine until i press browser's back button , when i press back button my external javascript doesn't work.

i used javascript in several way such as ( import - require - putting them in index.html and ...) for testing but the result was the same

i also used below code to detect back

router.events.subscribe((event: NavigationStart) => {
     if (event.navigationTrigger === 'popstate') {
     // window.location.reload();
   }     
});

notice that i don't want to reload the entire page. is this angular bug ? or what ?

Tahmasb
  • 41
  • 7

1 Answers1

0

My environment says "Property 'navigationTrigger' does not exist on type 'NavigationStart'." when I try your code, so you never enter in your if statement.

But your problem has already been posted : Angular 2 How to detect back button press using router and location.go()?

PS: Be careful to make the difference between angular 2+ and angularjs :p

Cyril
  • 13
  • 4
  • my problem is not detecting the back button , i can detect it , but my javascript doesn't work after pressing back – Tahmasb Mar 06 '20 at 13:24
  • My bad, sorry for my wrong response. But I don't understand what you mean by "javascript doesn't work after pressing". Can you be more specific ? what code should run after you pressed the button ? – Cyril Mar 06 '20 at 13:29
  • i have an external javascript file that run every time page loads but when press back button i think that javascript file doesn't load anymore :) – Tahmasb Mar 06 '20 at 13:40
  • hmm... your page isn't reload after a back button pressed event, so I think you have to reload / recall your javascript file when you catch the event. You can look after angular routing events to detect when reload your file too... – Cyril Mar 06 '20 at 14:12