# 移动设备上的 URL 哈希/锚点被剥离。如何阻止这种情况？

**URL:** <https://meta.discourse.org/t/hash-anchors-are-being-stripped-from-urls-on-mobile-how-to-stop-that/408505>\
**Category:** Support\
**Tags:** mobile\
**Created:** [2026年七月25日 09:10 UTC](https://meta.discourse.org/t/hash-anchors-are-being-stripped-from-urls-on-mobile-how-to-stop-that/408505 "2026-07-25T09:10:40Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![one1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/one1/32/493591_2.png) [@one1](https://meta.discourse.org/u/one1)\
**Post date:** [2026年七月25日 09:10 UTC](https://meta.discourse.org/t/hash-anchors-are-being-stripped-from-urls-on-mobile-how-to-stop-that/408505/1 "2026-07-25T09:10:40Z")

</div>

在桌面端点击带有锚点的链接时，页面会滚动到相应位置。但在移动端（Android 上的 Firefox 和 Chrome）上，锚点会被从 URL 中移除，因此无法滚动到指定位置。

_ **我的目标：** _

我们有一份较长的指南和常见问题解答文档，需要链接到各个标题。由于 Discourse 会移除 `id` 参数，我创建了一个[简单的主题组件](https://github.com/suttacentral/discourse-d-d-scroll-to-data-attributes)，该组件使用目标文档中的自定义数据属性，并监听 URL 中的锚点，以便滚动到具有匹配数据属性的元素。

它在桌面端可以正常工作！

然而在移动端，锚点似乎被移除了，导致进入目标页面时不会滚动到正确的元素。当然，对于长文档而言，移动端是最需要这种导航功能的场景。

我发现，由_目录组件_生成的锚点在新标签页中打开时是有效的。它们不会从 URL 中移除，浏览器也会滚动到正确的位置。

我该如何解决这个问题？

---

_[View the full topic](https://meta.discourse.org/t/hash-anchors-are-being-stripped-from-urls-on-mobile-how-to-stop-that/408505)._
