i am using following code to create a external js and integrate it on each route(page)
if(document.getElementById('mainJs') !=null){
document.getElementById('mainJs').remove();
}
const main = document.createElement('script');
main.src = '../assets/js/main.js';
main.type = 'text/javascript';
main.async = false;
main.id = "mainJs";
main.charset = 'utf-8';
document.getElementsByTagName('head')[0].appendChild(main);
but whenever the route switches my external js stops working
i am not sure if this is exactly the reason but in the chrome's Event-Listeners name of the js changes from Before Route Change to After Route Change
is the name change of the js causing this problem? if yes what should i do solve this?