dumi icon indicating copy to clipboard operation
dumi copied to clipboard

bug: dumi2.x hash history 模式下标题锚点与 TOC 行为异常

Open CJY0208 opened this issue 1 year ago • 1 comments

dumi 2.x hash history 模式下,标题锚点与 TOC 无法跳转至正确位置,

Versions

  • dumi: 2.1.5
  • node: 14.18.3
  • npm: 6.14.15
  • OS: Win10
  • Browser: Chrome 107.0.5304.63

Steps to reproduce

例如

---
// docs1.md
---

# Test

点击 Test 标题的锚点与对应 TOC

What is Expected?

本应跳转至 host.com/#/docs-1#Test

What is actually happening?

实际跳转至 host.com/#Test,进入了 404 页面

我看这个问题似乎在此 comment 有提到过,dumi 1x 中无此问题

修复建议

  • 标题锚点:基于 rehype-autolink-headings 实现,没找到切入点,目前本地是用纯 js 改写锚点 href 临时修复

    image

  • TOC:此处 生成 link 的逻辑追加 useLocation().pathname

    不过目前问题点在于不同主题包还没有对 TOC link 的统一处理方式,如果主题包改写了 TOC ,都可能需要额外处理 link,例如 dumi-theme-antd-style 对 TOC 的改写

CJY0208 avatar Mar 17 '23 02:03 CJY0208