Javascript 在Angular 8/9中,我可以确定app.module.ts中的URL并在声明模块时使用它吗?
我的app.module.ts中有一个第三方模块,需要知道用户登录时的url中是否有“www”,以便在身份验证后正确重定向。因此,安装程序如下所示: 应用程序模块.tsJavascript 在Angular 8/9中,我可以确定app.module.ts中的URL并在声明模块时使用它吗?,javascript,angular,authentication,angular8,angular9,Javascript,Angular,Authentication,Angular8,Angular9,我的app.module.ts中有一个第三方模块,需要知道用户登录时的url中是否有“www”,以便在身份验证后正确重定向。因此,安装程序如下所示: 应用程序模块.ts ... @NgModule({ declarations: [ AppComponent ], imports : [ ... ThirdPartyAuthModule.initAuth(environment.authConfig),
...
@NgModule({
declarations: [
AppComponent
],
imports : [
...
ThirdPartyAuthModule.initAuth(environment.authConfig),
...
],
bootstrap : [
AppComponent
]
})
export class AppModule
{
}
我想把url放到authConfig变量中。使用Angular可以吗?您可以始终使用window.location.href
实际上,您可以使用
APP\u初始值设定项并在其中写入逻辑。
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { environment } from '../environments/environment';
const authConfig = environment.authConfig;
// Add param below to your auth config
const href = window.location.href;
const isHttp = href.includes('http://');
const isHttps = href.includes('https://');
const hasWWW = href.includes('www');;
@NgModule({
imports: [
BrowserModule,
FormsModule,
// ThirdPartyAuthModule.initAuth(authConfig),
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }