html - html <base> 标签的空 href 是什么意思?

标签 html angular base-tag

假设我的页面 URL 是:http://example.com/path/to/dir/index.html
我通过以下方式代理此页面:http://proxyserver.com/path/to/dir/index.html .
同样,我希望页面中的所有相对 URL 都由 proxyserver.com 解析而不是 example.com .什么才是正确的<base> href 值?

我想要页面上的相对 URL,例如

  • newfile.html解决到 http://proxyserver.com/path/to/dir/newfile.html
  • /newfile.html解决到 http://proxyserver.com/newfile.html
  • #hash解决到 http://proxyserver.com/path/to/dir/file.html#hash

  • 设置 <base href="" />在页面中正确完成工作,但它有一些含义吗?它在浏览器之间有不同的解释吗?什么是空href值究竟是什么意思?它适用于所有框架,如 angular 吗?

    我听说<base>标记对于 Angular 应用程序的初始化是必需的,因此删除 <base>标签可能不起作用。

    注意:该网站可能已经包含一些 <base>我总是想覆盖的标签。

    我也试过 <base href="/" />但它会解析相对 URL
  • newfile.htmlhttp://proxyserver.com/newfile.html
  • #hashhttp://proxyserver.com/#hash这是错误的。

  • 任何帮助都受到高度赞赏。

    最佳答案

    <base href="" />定义所有相对路径的基础。
    它遵循高地原则(“只有一个”):-)

    只是为了检查我是否理解你的目标。你写了:

  • newfile.html解决到 http://proxyserver.com/path/to/dir/newfile.html
  • /newfile.html解决到 http://proxyserver.com/newfile.html

  • 所以你不想有一个基本路径,但你希望浏览器检查多个路径,如果有你需要的文档?

    这并不容易(从浏览器的 Angular 来看)。原因是浏览器不知道这些路径的内容。他必须向这些服务器创建请求“嘿,不错的服务器,您的目录中有“newfile.html”吗?没有?好的,谢谢。

    就像@Attersson 所说,如果你想实现这一点,你必须在你的网络服务器中创建过滤器和路由。这对客户来说不是工作。

    现在关于 Angular。
    在 Angular 6 中,你会写 <base href="/">在你的 index.html 中。
    然后在 Angular.json 中配置你真正想要的基本路径:
    ...
    "architect": {
            "build": {
              "builder": "@angular-devkit/build-angular:browser",
              "options": {
                 ...
                "baseHref": "/myLovedPath/",
    ...
    

    因此,Angular 将构建应用程序并更改 <base href="/"><base href="/myLovedPath/">
    温暖的问候

    关于html - html <base> 标签的空 href 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51416749/

    相关文章:

    html - 为什么我的页脚不在页面底部?

    html - 如何通过单击链接在另一个浏览器实例中打开页面

    javascript - 在 Angular2 中的嵌套组件上应用 css 规则

    javascript - Angular AuthGuard - 这是一个正确的解决方案吗?

    html - html <base> 标签的建议是什么?

    html - -ms-用户选择 : none bugged in IE11

    php - 如何在 Jquery : 48 function calls (96 lines each) for HTML class variable 中管理空间

    Angular2如何使用默认值设置单选按钮

    javascript - 如何让 testcafe 尊重 `<base>` 标签