mipengine / mip

[Deprecated] 请查看 mip2
https://www.mipengine.org/
MIT License
380 stars 81 forks source link

MIP 中锚点定位问题 #292

Open xuexb opened 6 years ago

xuexb commented 6 years ago

源代码(示例):

<a href="#">#</a>
<a href="#1">#1</a>
<a href="#2">#2</a>
<a href="#a">#a</a>

经过 MIP-Cache 解析后(示例):

<a href="https://static.xuexb.com/html/test-anchor.html#">#</a>
<a href="https://static.xuexb.com/html/test-anchor.html#1">#1</a>
<a href="https://static.xuexb.com/html/test-anchor.html#2">#2</a>
<a href="https://static.xuexb.com/html/test-anchor.html#a">#a</a>

而又命中了核心代码的链接规则:

https://github.com/mipengine/mip/blob/2af390cf5f2fa4746efa212bd568230489cea144/src/viewer.js#L235-L263

导航经过 MIP-Cache 后(线上),原生的 HTML 锚点不能使用,点击直接跳转到源站了。

xuexb commented 6 years ago

期望的:

  1. MIP-Cache 不应该对页面中的 href="#" 开头的锚点进行转换
  2. 如果是锚点链接,在线上环境不应该 window.top.location.href 跳转,应该走浏览器原生的逻辑,毕竟原生态,健康品。
xuexb commented 6 years ago

AMP-Cache 结果:

<a href=#>#</a>
<a href=#1>#1</a>
<a href=#2>#2</a>
<a href=#a>#a</a>

示例:https://static-xuexb-com.cdn.ampproject.org/v/s/static.xuexb.com/html/test-anchor-amp.html?d=1&amp_js_v=0.1&usqp=mq331AQGCAEYASAB#