也许我的整个想法是错误的,所以让我们检查一下。我有以下 HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<base href="/xyz">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<app-root></app-root>
<script src="runtime.js" defer=""></script><script src="polyfills.js" defer=""></script><script src="main.js" defer=""></script></body>
</html>
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试使用以下网址在浏览器中加载它时:http://localhost:8080/xyz 它会加载index.html,但对于所有资产(样式和javascript文件)我得到404
我希望,因为我有那个基本的 href="/xyz",它会在所有资源 URL 前面加上该 URL,但正如你所看到的,它没有。
为了完整起见,这是我的文件结构:
./server.js
./xyz/index.html
styles.css
.....
Run Code Online (Sandbox Code Playgroud)
所以服务器正在为/xyz路径中的所有文件提供服务
相对路径的解析方法是获取基本 URL ( ),删除路径中http://localhost:8080/xyz最后一个之后的所有内容(给您),然后附加新路径 ( )。/http://localhost:8080/http://localhost:8080/styles.css
如果你愿意/xyz/styles.css,那么你需要/在基本路径的末尾添加一个:<base href="/xyz/">
| 归档时间: |
|
| 查看次数: |
847 次 |
| 最近记录: |