# renderInOutlet遇到问题

**URL:** <https://meta.discourse.org/t/trouble-with-renderinoutlet/359690>\
**Category:** Development\
**Created:** [2025年三月31日 18:14 UTC](https://meta.discourse.org/t/trouble-with-renderinoutlet/359690 "2025-03-31T18:14:10Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2025年三月31日 18:14 UTC](https://meta.discourse.org/t/trouble-with-renderinoutlet/359690/1 "2025-03-31T18:14:10Z")

</div>

我一定是在做一些非常愚蠢的事情，但我就是看不出来。我希望在这里发帖能让我看出来，这样我就可以在别人知道我有多蠢之前删除它。

“HELLO WORLD”应该会显示在主页上。我在控制台中看到了“THIS IS THE HOMEPAGE”。我知道它在运行。但它不在那里。

然后我尝试添加“Extra item”，因为我没有其他想法了。它也没有显示出来。

在我将文件重命名为 .`gjs` 之前，我确实收到了一些错误，这进一步证明它正在关注该文件并且正在做一些事情。

```javascript
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>);
    }
  });
});

```

---

_[View the full topic](https://meta.discourse.org/t/trouble-with-renderinoutlet/359690)._
