그렇게 생각했는데요, 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);
}
});
}
});
출력이 전혀 나오지 않습니다…