そう思ったのは、すでに api.onPageChange(url) が正常に実行されているからです。なお、私は こちら のコードを適応しているため、setupComponent メソッド内で api オブジェクトにアクセスできることは間違いありません。
さらに明確にするために、現時点での状況を以下に示します。
次のコードでは、
<script type="text/discourse-plugin" version="0.8">
const user = api.getCurrentUser();
console.log("/u/" + user.username + "/billing/subscriptions");
api.registerConnectorClass("above-user-profile", "back-button", {
setupComponent(args, component) {
api.onPageChange((url) => {
if (url === "/u/" + user.username + "/billing/subscriptions" ){
document.querySelector("html").classList.add("custom-homepage");
component.set("displayCustomHomepage", true);
} else {
document.querySelector("html").classList.remove("custom-homepage");
component.set("displayCustomHomepage", false);
}
});
}
});
コンソールから正しい出力 /u/Miles/billing/subscriptions が得られます。しかし、以下のようにすると、
<script type="text/discourse-plugin" version="0.8">
api.registerConnectorClass("above-user-profile", "back-button", {
setupComponent(args, component) {
const user = api.getCurrentUser();
console.log("/u/" + user.username + "/billing/subscriptions");
api.onPageChange((url) => {
if (url === "/u/" + user.username + "/billing/subscriptions" ){
document.querySelector("html").classList.add("custom-homepage");
component.set("displayCustomHomepage", true);
} else {
document.querySelector("html").classList.remove("custom-homepage");
component.set("displayCustomHomepage", false);
}
});
}
});
出力は何も得られません。