问题描述
类似的问题,没有适当的答案.
如果我在app.module.ts中设置:
providers: [
{ provide: APP_BASE_HREF, useValue: '/my/app'},
然后输入localhost:4200/my/app
this.location.path()
返回正确的路径".
但是,如果我键入localhost:4200/my/App
this.location.path()
返回"/my/App",这是错误的.
出于这个问题之外的原因,我检查了URL.所以我的问题是:如何使基本href大小写不敏感?
我认为在IIS上安装失败的原因相同.
我认为最好的方法可能是强制IIS通过使用重写规则将用户重定向到my/app
.但是我不知道IIS,所以我不能给您解决方案.如果要按角度进行,可以使用以下代码.它通过工厂动态提供APP_BASE_HREF
令牌
export function baseHrefFactory()
{
let expectedBaseHref = '/my/app';
let currentBaseHref = window.location.pathname.substr(0, expectedBaseHref.length);
//Add checks herre if needed
return currentBaseHref;
}
@NgModule({
/**/
providers: [
{provide: APP_BASE_HREF, useFactory: baseHrefFactory}
]
})
export class AppModule
There is similar question without proper answer.
If I set in app.module.ts:
providers: [
{ provide: APP_BASE_HREF, useValue: '/my/app'},
and type localhost:4200/my/app
this.location.path()
returns the correct path "".
However if I type localhost:4200/my/App
this.location.path()
returns "/my/App" which is wrong.
For reasons beyond this question I make checks for the URL. So my question is: how to make base href case insensitive?
I assume that installation on IIS fails for same reason.
I think the best way may be to force IIS to redirect the user to my/app
by using rewrite rules. However I don't know IIS, so I cannot give you a solution.
If you want to do it in angular, you could use the following code. It provides APP_BASE_HREF
token dynamically with a factory
export function baseHrefFactory()
{
let expectedBaseHref = '/my/app';
let currentBaseHref = window.location.pathname.substr(0, expectedBaseHref.length);
//Add checks herre if needed
return currentBaseHref;
}
@NgModule({
/**/
providers: [
{provide: APP_BASE_HREF, useFactory: baseHrefFactory}
]
})
export class AppModule
这篇关于如何使基本的href/IIS虚拟目录对angular应用程序不区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!