简体   繁体   English

为什么`replaceState`删除`/ basehref / index.html`中的`index.html`

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

I have the /is/ set as base href and the following simple code in the index.html that uses replaceState() : 我将/is/设置为基本href,并在使用replaceState()index.html中设置了以下简单代码:

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

The URL before the code is executed looks like this: 执行代码之前的URL如下所示:

http://localhost:8080/index.html

However, once the code is executed the index.html is gone and the URL looks like this: 但是,执行代码后, index.html消失了,URL如下所示:

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

I expected it to look like this: 我希望它看起来像这样:

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

Why is index.html gone? 为什么index.html不见了?

The <base> tag establishes the document base URL. <base>标记建立文档基础URL。 That serves as the reference point for all relative URLs in APIs like the History API. 用作历史API之类的API中所有相对URL的参考点。 That's kind-of the whole point of <base> . 这就是<base>

The "current" URL is called the "fallback base URL" in the W3C specs, and it only comes into play when there's no <base> tag with a specified href value. 在W3C规范中,“当前” URL被称为“后备基本URL”,只有在没有具有指定href值的<base>标记时,它才起作用。

So the answer is basically that that's the way things work. 因此,答案基本上就是事情的运作方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM