我以前从未见过 实际使用过的<base>HTML标签.它的使用存在缺陷,这意味着我应该避免它吗?
事实上我从来没有注意到它在现代生产网站(或任何网站)上的使用让我对它持怀疑态度,尽管看起来它可能有用于简化我网站链接的有用应用程序.
使用基本标签几周后,我最终找到了使用基本标签的一些主要问题,这使得它比最初出现时更不可取.从本质上讲,变化href='#topic'和href=''基本标签下是非常有它们的默认行为不兼容,并可以从默认行为,这种变化很容易使第三方库的控制范围之外的非常不可靠的 以意想不到的方式,因为它们在逻辑上依赖于默认行为.通常,这些更改是微妙的,并且在处理大型代码库时会导致不那么明显的问题.我已经创建了一个回答,详细说明了我在下面遇到的问题.因此,在您进行广泛部署之前,请自行测试链接结果<base>,这是我的新建议!
我们有一个企业应用程序,它为客户端使用Angular 2.我们每个客户都有自己独特的网址,例如:https://our.app.com/customer-one和https://our.app.com/customer-two.目前我们可以<base href...>动态设置document.location.所以用户点击https://our.app.com/customer-two并<base href...>设置为/customer-two......完美!
问题是,如果用户是例如,https://our.app.com/customer-two/another-page并且他们刷新页面或尝试直接点击该URL,则<base href...>设置为get /customer-two/another-page并且找不到资源.
我们尝试了以下无济于事:
<!doctype html>
<html>
<head>
<script type='text/javascript'>
var base = document.location.pathname.split('/')[1];
document.write('<base href="/' + base + '" />');
</script>
...
Run Code Online (Sandbox Code Playgroud)
不幸的是,我们的想法很新鲜.任何帮助都会很棒.
我正在构建Chrome浏览器操作扩展.
我正在尝试将Angular 2应用程序加载到Chrome中的弹出窗口中.
我在使用Angular 1.5之前已经这样做了,但尝试使用Angular 2并收到错误.
未处理的承诺拒绝:没有基本的href设置.请提供APP_BASE_HREF标记的值或向文档添加基本元素.; 区域:; 任务:Promise.then; 值:错误:没有设置基本href.请提供APP_BASE_HREF标记的值或向文档添加基本元素.(...)错误:没有设置基本href.请提供APP_BASE_HREF标记的值或向文档添加基本元素.
我把<base href="/">标签放到我的popu.html中.但问题是,vendor.js和main.js被Chrome下载(并且在被popup.html加载之前),所以没有HTML页面放在哪里<base href="/">
只是想知道如何解决这个问题.
Popup.html
<!doctype html>
<html>
<head>
<base href="/">
<meta charset="utf-8">
<title>FountainJS</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="icon" type="image/png" href="http://fountainjs.io/assets/imgs/fountain.png"/>
<link href="../styles/popup.css" rel="stylesheet">
</head>
<body>
<div style="width: 200px; height: 150px;">
<fountain-root>My Awesome Chrome Popup should load with Angular 2 right Here</fountain-root>
<script type="text/javascript" src="../scripts/vendor.js"></script>
<script type="text/javascript" src="../scripts/main.js"></script>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)