我正在使用Angular 5应用,正在将其托管在Apache2.4 HTTP服务器上,并使用代理模块对其进行重定向 http://localhost:7777/test/
我的第一个问题是调用从浏览器服务时,它是使用http://localhost:7777/
作为基本URL,从我的测试服务中删除斜杠尽快解决,/service1/upload
给service1/upload
。所以我从http://localhost:7777/service1/upload
到了http://localhost:7777/test/service1/upload
。
现在我image.png
在Assets /文件夹中还有一个其他未解决的问题,它一直试图从中获取它,http://localhost:7777/assets/image.png
而不是http://localhost:7777/test/assets/image.png
我测试了第二个URL,它按要求返回了我的图像。如何使Angular 5相对地找到我的资产路径?以我为例http://localhost:7777/test/assets/image.png
这是我访问HTML图像的方法:
..
<img src='assets/stop_pic.PNG' >
..
我的基本href在我的index.html中:
<base href="">
我的angular-cli.json conf:
...
apps": [
{
"root": "src",
"outDir": "../src/main/resources/static",
"assets": [
"assets"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
...
得到了答案,即使这有点愚蠢。浏览器缓存了我的应用程序,因此它没有计入我从<img src='../../assets/stop_pic.PNG'>
到的最后一次修改<img src='assets/stop_pic.PNG'>
。从我的图像中删除所有斜杠src起作用了!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句