How to re-execute scripts in theme components

Scripts in theme components execute only once; how do I re-execute them when there is a route change(not full page refresh)?

For example, I want the scripts in a component to execute even after navigating between tags.

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

Where would this if I’m building a theme component? This is my code at the moment. I’m trying to re-render the footer every time there’s a route change so that the scripts would re-execute.

I’m getting weird errors.

I’m a total beginner, and I don’t know if this is the right way to go about this.

    initialize() {
      withPluginApi("0.8", api => {
        if (settings.Show_footer_on_login_required_page) {
          api.modifyClass("controller:static", {
            @on("init")
            showFooterOnStatic() {
              this.set("application.showFooter", true);
            }
        });

        api.onPageChange(() => {
          showFooterOnStatic() {
            this.set("application.showFooter", true);
          }
        });
      }
    });
1 Like

Have you tried looking at prior art/work/code in another similar theme-component to get some insights on how to go about it?

1 Like

I have looked at some, but they don’t seem to have what I’m trying to do. I guess I will look at more theme-component

1 Like

Thanks, @osioke, and @michaeld :raised_hands:, I found exactly what I’ve been looking for after going through this theme-component: Homepage Feature Component

4 Likes