小编Dhi*_*dia的帖子

资产未考虑基本href网址-找不到错误

我只是在Webform项目中复制了我的角度构建脚本,然后将该项目部署在IIS中。

注意:我只复制了脚本文件,没有在IIS中单独部署。

我已经在webform项目的Scripts文件夹内复制了angular dist文件夹。

现在我的基本网址是: http:// localhost / Angular2 /

-在角度我已经设置了基本href,以“../../Scripts/dist”里面的index.html文件。

一切工作正常,如路由,加载图像,js文件等。仅svg图标未加载,并出现404 Not Found错误。

对于Angular页面,除svg外,所有内容(css,jpg,js)均从http://localhost/Angular2/Scripts/dist/main.js等加载 。

但是svg图标正在尝试从路径
http://localhost/Angular2/assets/features/home.svg获取负载,而不是从http://localhost/Angular2/Scripts/dist/assets/features/home.svg

我不确定为什么对于svg图标,基本href无法正常工作。

下面是我使用材质库使用svg图标的代码。

constructor(iconRegistry: MatIconRegistry, sanitizer: DomSanitizer) {
    iconRegistry.addSvgIcon('home', sanitizer.bypassSecurityTrustResourceUrl('/assets/features/home.svg'));
    iconRegistry.addSvgIcon('library', sanitizer.bypassSecurityTrustResourceUrl('/assets/features/library.svg'));
    iconRegistry.addSvgIcon('guest', sanitizer.bypassSecurityTrustResourceUrl('/assets/features/guest.svg'));
Run Code Online (Sandbox Code Playgroud)

如果我用下面的一行修改了上面的行,那么它工作正常。

constructor(iconRegistry: MatIconRegistry, sanitizer: DomSanitizer) {
    iconRegistry.addSvgIcon('home', sanitizer.bypassSecurityTrustResourceUrl('Scripts/dist/assets/features/home.svg'));
    iconRegistry.addSvgIcon('library', sanitizer.bypassSecurityTrustResourceUrl('Scripts/dist/assets/features/library.svg'));
    iconRegistry.addSvgIcon('guest', sanitizer.bypassSecurityTrustResourceUrl('Scripts/dist/assets/features/guest.svg'));
Run Code Online (Sandbox Code Playgroud)

我可以知道为什么base href不申请SVG图标吗?

提前致谢。

assets base href http-status-code-404 angular

1
推荐指数
1
解决办法
1608
查看次数

标签 统计

angular ×1

assets ×1

base ×1

href ×1

http-status-code-404 ×1