How to use api.onPageChange with api.createWidget?

Hi again, I’m trying to figure out the best way to only make the widget show on a specific URL, such as the homepage.

The easy way is simply to use a plugin outlet that only exists on the homepage, which works for what I need for now (specifically, the discovery-navigation-bar-above). But I’m still curious about how to do this programmatically in a way that is sensitive to the specific page URL.

I found this very helpful topic, also by @awesomerobot :

I tried to adapt this into the solution from earlier in this post:

        api.onPageChange((url) => {
            if (url === "/" || url === homeRoute ){
               this.scheduleRerender();
            }
        });

But this still makes the image appear on all pages. I also tried to put my variables and random selection code inside the if clause, but that doesn’t work at all.

There’s also the <script type="text/x-handlebars" ... section of the example, but it seems to only allow for HTML, and I don’t know how to get the variables into it from the previous script.