# How to re-execute scripts in theme components

**URL:** https://meta.discourse.org/t/how-to-re-execute-scripts-in-theme-components/191394
**Category:** Development
**Created:** [May 23, 2021, 5:40pm UTC](https://meta.discourse.org/t/how-to-re-execute-scripts-in-theme-components/191394 "2021-05-23T17:40:12Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Marvelxy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marvelxy/32/218786_2.png) [@Marvelxy](https://meta.discourse.org/u/Marvelxy)
#### Post date: [May 23, 2021, 5:40pm UTC](https://meta.discourse.org/t/how-to-re-execute-scripts-in-theme-components/191394/1 "2021-05-23T17:40:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [May 23, 2021, 8:56pm UTC](https://meta.discourse.org/t/how-to-re-execute-scripts-in-theme-components/191394/2 "2021-05-23T20:56:29Z")

</div>

```plaintext
<script type="text/discourse-plugin" version="0.8">
    api.onPageChange(() => {
        // your code
    });   
</script>

```

---

<div class="post-metadata">

### Author: ![Marvelxy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marvelxy/32/218786_2.png) [@Marvelxy](https://meta.discourse.org/u/Marvelxy)
#### Post date: [May 23, 2021, 9:38pm UTC](https://meta.discourse.org/t/how-to-re-execute-scripts-in-theme-components/191394/3 "2021-05-23T21:38:25Z")

</div>

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.

```plaintext
    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);
          }
        });
      }
    });

```

---

<div class="post-metadata">

### Author: ![osioke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/osioke/32/238946_2.png) [@osioke](https://meta.discourse.org/u/osioke)
#### Post date: [May 24, 2021, 1:39pm UTC](https://meta.discourse.org/t/how-to-re-execute-scripts-in-theme-components/191394/4 "2021-05-24T13:39:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Marvelxy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marvelxy/32/218786_2.png) [@Marvelxy](https://meta.discourse.org/u/Marvelxy)
#### Post date: [May 24, 2021, 3:47pm UTC](https://meta.discourse.org/t/how-to-re-execute-scripts-in-theme-components/191394/5 "2021-05-24T15:47:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Marvelxy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marvelxy/32/218786_2.png) [@Marvelxy](https://meta.discourse.org/u/Marvelxy)
#### Post date: [May 24, 2021, 10:17pm UTC](https://meta.discourse.org/t/how-to-re-execute-scripts-in-theme-components/191394/6 "2021-05-24T22:17:48Z")

</div>

Thanks, @osioke, and @michaeld 🙌, I found exactly what I’ve been looking for after going through this theme-component: [Homepage Feature](https://meta.discourse.org/t/homepage-feature-component/144264)

[https://github.com/discourse/discourse-homepage-feature-component/blob/main/javascripts/homepage-featured-topics/connectors/above-main-container/homepage-featured-topics.js.es6](https://github.com/discourse/discourse-homepage-feature-component/blob/main/javascripts/homepage-featured-topics/connectors/above-main-container/homepage-featured-topics.js.es6)
