Ensure imported JavaScript files will work after switched routes

Hello guys,

I’m working on a project right now and I’m facing some issues that I’d like to share. I bought a theme which is not built for meteor. It’s actually a pure HTML that I’m adapting to a Meteor way.

It is said to import some JS files in order to make it work correctly. After having some troubles, I managed to import them in a way that it’s possible to load them correctly:

Template.ApplicationLayout.onRendered(function () {
    import '../ui/components/js/core/source/App.js';
    import '../ui/components/js/core/source/AppNavigation.js';
    import '../ui/components/js/core/source/AppOffcanvas.js';
    import '../ui/components/js/core/source/AppCard.js';
    import '../ui/components/js/core/source/AppForm.js';
    import '../ui/components/js/core/source/AppNavSearch.js';
    import '../ui/components/js/core/source/AppVendor.js';
});

However, whenever I switch between routes, they kinda stop working, it’s possible to see some bugs on the HTML. I’m using iron-router to track it.

I was wondering if there would be a way to ensure that the JS was load properly and won’t stop working, regardless of switched routes.

Thanks in advance.