资产不考虑基本href网址-找不到错误 [英] Assets not cosidering base href url - not found error

查看:90
本文介绍了资产不考虑基本href网址-找不到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Webform项目中复制了我的角度构建脚本,并将该项目部署在IIS中.

I just copied my angular build scripts within my webform project and deployed that project in IIS.

注意:我只复制了不在IIS内部单独部署的脚本文件.

Note: I have only copied scripts file not deployed separately inside the IIS.

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

I have copied angular dist folder inside the Scripts folder in webform project.

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

Right now my base url is: http://localhost/Angular2/

在Angular中,我已将 base href 设置为" index.html 中的" ../../Scripts/dist" > 文件.

In Angular I have set the base href to "../../Scripts/dist" inside index.html file.

一切正常,例如路由,加载图像,js文件等.只有svg图标没有加载,并出现 404 Not Found 错误.

Everything is working fine like routing, loading images, js files etc. Only svg icons are not getting loaded and getting 404 Not Found error.

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

For Angular page, except svg, everything(css,jpg,js) is loaded from http://localhost/Angular2/Scripts/dist/main.js etc.

但是svg图标正在尝试从路径获取负载
http://localhost/Angular2/assets/features/home.svg 代替 http://localhost/Angular2/脚本/dist/assets/features/home.svg

But the svg icons are trying to get load from path
http://localhost/Angular2/assets/features/home.svg in stead of http://localhost/Angular2/Scripts/dist/assets/features/home.svg

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

I am not sure why for svg icons, base href is not working.

下面是我在材质库中使用svg图标的代码.

Below is the code where I am using svg icons using material library.

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'));

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

If I modified the above lines with the below one then it is working fine.

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'));

我可以知道为什么基本href不申请svg图标吗?

May I know why base href is not applying for svg icons?

谢谢.

推荐答案

尝试使用相对路径:

改变

'/assets/features/home.svg'

'./assets/features/home.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'));

这篇关于资产不考虑基本href网址-找不到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆