# 在组件中，如何找出论坛的基本 URI？

**URL:** https://meta.discourse.org/t/in-a-component-how-do-i-find-out-the-base-uri-of-the-forum/370106
**Category:** Development
**Created:** [2025 年6 月 13 日 17:29 UTC](https://meta.discourse.org/t/in-a-component-how-do-i-find-out-the-base-uri-of-the-forum/370106 "2025-06-13T17:29:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Willy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/willy/32/499930_2.png) [@Willy](https://meta.discourse.org/u/Willy)
#### Post date: [2025 年6 月 13 日 17:29 UTC](https://meta.discourse.org/t/in-a-component-how-do-i-find-out-the-base-uri-of-the-forum/370106/1 "2025-06-13T17:29:12Z")

</div>

如果我的组件安装在三个不同的论坛上：

> [https://forum.someone.com/](https://forum.someone.com/)  
> [https://other.com/forum](https://other.com/forum)  
> [https://player.com/](https://player.com/)

如果我在子目录中，例如 `https://forum.someone.com/mytopic/blablaba`，我该如何提取基本 URI？

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [2025 年6 月 13 日 17:33 UTC](https://meta.discourse.org/t/in-a-component-how-do-i-find-out-the-base-uri-of-the-forum/370106/2 "2025-06-13T17:33:13Z")

</div>

我想你可能在找这个功能，它还没有合并

> [@How do I add links to site settings into the settings description of my component?](https://meta.discourse.org/t/how-do-i-add-links-to-site-settings-into-the-settings-description-of-my-component/368531/3?u=lilly):
>
> Once this PR is merged, you’ll be able to use %{base\_path} in theme setting descriptions:

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [2025 年6 月 13 日 20:59 UTC](https://meta.discourse.org/t/in-a-component-how-do-i-find-out-the-base-uri-of-the-forum/370106/3 "2025-06-13T20:59:14Z")

</div>

您想在哪里使用它？  
例如，类似 Reddit 的主题在模板中使用 `discourse/helpers/base-path` 来创建右侧欢迎消息中的“类别列表”链接。

 ![image](https://global.discourse-cdn.com/meta/original/4X/4/1/9/41941145fa0259865c8661a5b054502a2a3edeb3.png)

> <https://github.com/discourse/discourse-redditish-theme/blob/01cf318072cb5aeff176bdf78083cf46592ccdcc/javascripts/discourse/components/sidebar-welcome.gjs#L6>

> <https://github.com/discourse/discourse-redditish-theme/blob/01cf318072cb5aeff176bdf78083cf46592ccdcc/javascripts/discourse/components/sidebar-welcome.gjs#L41>

> <https://github.com/discourse/discourse-redditish-theme/blob/01cf318072cb5aeff176bdf78083cf46592ccdcc/locales/en.yml#L5-L5>

还有一些示例在 JavaScript 函数中使用 `discourse/lib/get-url` 来获取 URL。
