# 我如何编辑使用 api.addCommunitySectionLink 添加的侧边栏链接？

**URL:** <https://meta.discourse.org/t/how-can-i-edit-sidebar-links-that-are-added-with-api-addcommunitysectionlink/357629>\
**Category:** Development\
**Created:** [2025 年3 月 17 日 19:18 UTC](https://meta.discourse.org/t/how-can-i-edit-sidebar-links-that-are-added-with-api-addcommunitysectionlink/357629 "2025-03-17T19:18:08Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

作者： ![manuel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/manuel/32/468169_2.png) [@manuel](https://meta.discourse.org/u/manuel)\
发布日期： [2025 年3 月 18 日 16:43 UTC](https://meta.discourse.org/t/how-can-i-edit-sidebar-links-that-are-added-with-api-addcommunitysectionlink/357629/5 "2025-03-18T16:43:47Z")

</div>

如果无法在自定义模态框中修改新链接，我想我暂时会放弃添加它们的想法。在自定义模态框中添加一个难以捉摸的链接似乎会令人困惑。

但是，我希望（如果手动添加了）链接在相关路由上时能够高亮显示，所以我现在将添加这个：

```plaintext
import { apiInitializer } from "discourse/lib/api";

export default apiInitializer("0.8", (api) => {
  const router = api.container.lookup("service:router");

  api.onPageChange(() => {
    const currentRoute = router.currentRoute.name;
    const customHomepageLink = document.querySelector(
      '.sidebar-section-link[href="/custom"]'
    );

    if (currentRoute === "discovery.custom") {
      if (customHomepageLink) {
        customHomepageLink.classList.add("active");
      }
    } else {
      if (customHomepageLink) {
        customHomepageLink.classList.remove("active");
      }
    }
  });
});

```

---

_[View the full topic](https://meta.discourse.org/t/how-can-i-edit-sidebar-links-that-are-added-with-api-addcommunitysectionlink/357629)._
