# "/t/XYZ#anchor" 在 XYZ 页面上不起作用

**URL:** https://meta.discourse.org/t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101
**Category:** Feature
**Created:** [2022 年4 月 23 日 18:42 UTC](https://meta.discourse.org/t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101 "2022-04-23T18:42:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Arthri](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arthri/32/211355_2.png) [@Arthri](https://meta.discourse.org/u/Arthri)
#### Post date: [2022 年4 月 23 日 18:42 UTC](https://meta.discourse.org/t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101/1 "2022-04-23T18:42:58Z")

</div>

你好！当帖子使用短链接 + 锚点 (`/t/id#anchor`) 链接到自身，并且在同一页面上点击该链接时，它会重定向到顶部而不是锚点，这里存在一个问题。

演示一下就更清楚了：

# Header 1

1. [#header-1](#header-1-1) 在此帖中点击时有效
2. \u003chttps://meta.discourse.org/t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101#header-1-1\u003e 在此帖中点击并引用时有效
3. \u003chttps://meta.discourse.org/t/a/225101#header-1-1\u003e 在此帖中点击并引用时有效
4. \u003chttps://meta.discourse.org/t/225101#header-1-1\u003e 在未在此帖中点击时有效
5. [/t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101#header-1-1](https://meta.discourse.org/t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101#header-1-1) 在此帖中点击并引用时有效
6. [/t/a/225101#header-1-1](https://meta.discourse.org/t/a/225101#header-1-1) 在此帖中点击并引用时有效
7. [/t/225101#header-1-1](https://meta.discourse.org/t/225101#header-1-1) 在未在此帖中点击时有效

* * *

我还注意到另外两个问题。除第一个链接外，所有链接都会重新加载页面。链接 2、3、5 和 6 有效，但锚点会在短时间内从 URL 中移除。

* * *

我最初的问题是，引用一个只包含锚点的帖子（指向同一页面的另一个部分）会导致锚点相对于当前页面而不是被引用的页面，而不是相对于被引用的页面。如果你引用这七个链接，第一个链接将指向 `CURRENT PAGE#header-1`。

我尝试了此 bug 报告中的解决方案（见下文）。它正确地链接到了页面，但锚点未被尊重。

> [@Quoting does not preserve hyperlink](https://meta.discourse.org/t/quoting-does-not-preserve-hyperlink/33141/2):
>
> And as you can see, above “For Example I will reply to this” is no longer a hyperlink.

---

<div class="post-metadata">

### Author: ![mrmowji](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrmowji/32/505517_2.png) [@mrmowji](https://meta.discourse.org/u/mrmowji)
#### Post date: [2025 年6 月 15 日 10:19 UTC](https://meta.discourse.org/t/t-xyz-anchor-doesnt-work-when-on-the-page-xyz/225101/2 "2025-06-15T10:19:15Z")

</div>

> [@Arthri](#):
>
> 我还注意到另外两个问题。除第一个链接外，所有链接都会重新加载页面。链接 2、3、5 和 6 可以工作，但 URL 中的标题会在短时间后被移除

我的 #anchor 变体也有这个问题。它不总是重新加载页面。也许只有当我第一次加载主题时点击这样的锚点时才会。不幸的是，我无法提供确切的步骤。

另外，“重新加载”不是指浏览器标签页的刷新。我指的是“Web 应用程序”重新加载；一个进度条会出现在视口的顶部。
