问题描述
有类似的问题没有正确答案.
There is similar question without proper answer.
如果我在 app.module.ts 中设置:
If I set in app.module.ts:
providers: [
{ provide: APP_BASE_HREF, useValue: '/my/app'},
然后输入 localhost:4200/my/app
and type localhost:4200/my/app
this.location.path()
返回正确的路径".
但是如果我输入 localhost:4200/my/App
However if I type localhost:4200/my/App
this.location.path()
返回错误的/my/App".
returns "/my/App" which is wrong.
出于这个问题之外的原因,我检查了 URL.所以我的问题是:如何使 base href 不区分大小写?
For reasons beyond this question I make checks for the URL. So my question is: how to make base href case insensitive?
我认为 IIS 上的安装由于同样的原因而失败.
I assume that installation on IIS fails for same reason.
推荐答案
我认为最好的方法可能是强制 IIS 使用重写规则将用户重定向到 my/app
.但是我不知道IIS,所以我不能给你一个解决方案.
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.
如果你想用 angular 来做,你可以使用下面的代码.它通过工厂动态提供APP_BASE_HREF
令牌
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
这篇关于如何使 Angular 应用程序的基本 href/IIS 虚拟目录不区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!