네, @manuel님의 솔루션은 상당히 간단하게 원하는 것을 달성하기 위한 좋은 접근 방식입니다. window.location.href를 사용하면 Ember의 runloop 때문에 올바른 URL을 가져오는 데 문제가 발생할 수 있습니다.
현재 하시는 작업을 더 "Ember"적인 방식으로 조정하려면 다음과 같은 방식으로 처리할 수 있습니다:
<script type="text/discourse-plugin" version="1.1.0">
api.onPageChange(() => {
const router = api.container.lookup('service:router');
if (router.currentRoute.name === 'discovery.top') {
document.querySelectorAll('#main-title')[0].style.display = 'none';
}
});
</script>
그러나 단순히 body 클래스를 추가하고 해당 클래스를 스타일링하는 것이 가장 좋은 방법일 수 있으며, 이렇게 하면 더 복잡한 스타일 변경도 할 수 있습니다.
<script type="text/discourse-plugin" version="1.1.0">
api.onPageChange(() => {
const router = api.container.lookup('service:router');
if (router.currentRoute.name === 'discovery.top') {
document.body.classList.add('route-discovery-top');
} else {
document.body.classList.remove('route-discovery-top');
}
});
</script>
.route-discovery-top #main-title {
display: none;
}