Current PageTracker.current?

Is there a new way to get a Javascript event when page URL changes? Discourse.PageTracker.current is not working for me.

I’ve had some luck with something like this. (May not be the most optimal way :sweat_smile:)

<script type="text/discourse-plugin" version="0.8.16">
api.onPageChange(() => {
	foo();
});

function foo() {
	// do stuff
	console.log(" foo loaded");
}
</script>

https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/plugin-api.js.es6#L341-L356

2 Likes

Thank you! That seems to be the best way currently. Also found it referenced here:

2 Likes