我一定是在做一些非常愚蠢的事情,但我就是看不出来。我希望在这里发帖能让我看出来,这样我就可以在别人知道我有多蠢之前删除它。
“HELLO WORLD”应该会显示在主页上。我在控制台中看到了“THIS IS THE HOMEPAGE”。我知道它在运行。但它不在那里。
然后我尝试添加“Extra item”,因为我没有其他想法了。它也没有显示出来。
在我将文件重命名为 .gjs 之前,我确实收到了一些错误,这进一步证明它正在关注该文件并且正在做一些事情。
import { apiInitializer } from "discourse/lib/api";
export default apiInitializer("1.8.0", (api) => {
// see if we're on the home page
api.onPageChange(() => {
const router = api.container.lookup("service:router");
const url = router?.currentURL;
const isHomePage = url === "/";
api.renderInOutlet("top-notices", <template>Extra item</template>);
if (isHomePage) {
console.log("THIS IS THE HOMEPAGE");
api.renderInOutlet("after-header", <template>HELLO WORLD</template>);
}
});
});