Javascript not re-running between different pages

Hi All,

I developed a theme component that rotates using the swiper.js library. In the head tag of my component I get the swiper js/css files from the CDN and also declare the element on the page as a swiper inside a window.ready function.

The issue I’m running into is that it rotates fine when you directly navigate to that page, but if you click on any link on the Discourse site that takes you to that page, the first slide is loaded but it is a static image and this component will not animate (rotate) until you refresh the page.

I have a suspicion this is due to the fact that the javascript is not re-running when navigating between pages in Discourse, instead content is just generated on different pages. Is this how Discourse works and, if so, is there a workaround to this?

You need to put this code in a theme component:

<script type="text/discourse-plugin" version="0.8">
    api.onPageChange(() =>{
        callYourFunctionHere();
    });
</script>
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.