我刚刚在 Webform 项目中复制了 Angular 构建脚本,并将该项目部署到 IIS 中。
注意:我只复制了脚本文件,没有单独部署在 IIS 中。
我已将 Angular dist 文件夹复制到 Webform 项目的 Scripts 文件夹中。
现在我的基本网址是:http://localhost/Angular2/ http://localhost/Angular2/
在 Angular 中我设置了基本href to “../../脚本/dist” inside 索引.html file.
一切都工作正常,如路由、加载图像、js 文件等。只有 svg 图标没有被加载和获取404 未找到 error.
对于 Angular 页面,除了 svg 之外,所有内容(css、jpg、js)均从以下位置加载http://localhost/Angular2/Scripts/dist/main.js http://localhost/Angular2/Scripts/dist/main.js etc.
但 svg 图标试图从路径获取负载
http://localhost/Angular2/assets/features/home.svg http://localhost/Angular2/assets/features/home.svg代替http://localhost/Angular2/Scripts/dist/assets/features/home.svg http://localhost/Angular2/Scripts/dist/assets/features/home.svg
我不知道为什么对于 svg 图标,base 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'));
如果我用下面的一行修改上面的行,那么它工作正常。
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'));
我可以知道为什么 base href 不适用 svg 图标吗?
提前致谢。