簡體   English   中英

為什么`replaceState`刪除`/ basehref / index.html`中的`index.html`

[英]Why `replaceState` removes `index.html` in `/basehref/index.html`

我將/is/設置為基本href,並在使用replaceState()index.html中設置了以下簡單代碼:

<base href="/is/">
<script>
    setTimeout(()=>{
        history.replaceState(null, "", "#/some");
    }, 2000);
</script>

執行代碼之前的URL如下所示:

http://localhost:8080/index.html

但是,執行代碼后, index.html消失了,URL如下所示:

http://localhost:8080/is/#/some

我希望它看起來像這樣:

http://localhost:8080/is/index.html#/some

為什么index.html不見了?

<base>標記建立文檔基礎URL。 用作歷史API之類的API中所有相對URL的參考點。 這就是<base>

在W3C規范中,“當前” URL被稱為“后備基本URL”,只有在沒有具有指定href值的<base>標記時,它才起作用。

因此,答案基本上就是事情的運作方式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM