Angular - AuthGuard 正在重定向 Iframe
Angular - AuthGuard is redirecting Iframe
我正在 angular 应用程序中实现 iFrame。当我直接在 html 中提供 src url 时,应用程序工作正常并加载请求的 UI。但是当我从后端获取 src url 并将其作为变量传递时,auth guard 将 url 重定向到登录页面。如何解决这个问题?
DefectsManagementComponent.html:
<div class="container-fluid dtep-style dtep-min-height-569px-minus-56px">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group"></div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group">
<iframe id="defects" class="col-lg-12 col-md-12 col-sm-12 col-xs-12" title="Defects Management" src="url">
</iframe>
</div>
</div>
</div>
</div>
DefectsManagementComponent.ts:
export class DefectsManagementComponent implements OnInit {
url: string;
constructor(private service: SolutionInstanceService) {
}
ngOnInit() {
this.service.fetchSolutionByName("DEFECT_MANAGEMENT").subscribe(data =>{
this.url = data["solutionURL"];
});
}
}
AppRoutingModule.ts:
const routes: Routes = [
{
path: "login",
component: LoginComponent
},
{
path: "home",
canActivate: [AuthGuardGuard],
component: HomeComponent
},
{
path: "defects",
component: DefectsManagementComponent
},
{
path: "",
redirectTo: "login",
pathMatch: "full"
},
{
path: "**",
redirectTo: "login",
pathMatch: "full"
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule
你应该在 src 周围使用方括号将 url 的值绑定到它,否则你将字符串“url”分配给 src。还可以在 iframe 上使用 ngIf 以仅在填充 url 时显示它。然后您需要清理 url。在 查看更多。
我正在 angular 应用程序中实现 iFrame。当我直接在 html 中提供 src url 时,应用程序工作正常并加载请求的 UI。但是当我从后端获取 src url 并将其作为变量传递时,auth guard 将 url 重定向到登录页面。如何解决这个问题?
DefectsManagementComponent.html:
<div class="container-fluid dtep-style dtep-min-height-569px-minus-56px">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group"></div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group">
<iframe id="defects" class="col-lg-12 col-md-12 col-sm-12 col-xs-12" title="Defects Management" src="url">
</iframe>
</div>
</div>
</div>
</div>
DefectsManagementComponent.ts:
export class DefectsManagementComponent implements OnInit {
url: string;
constructor(private service: SolutionInstanceService) {
}
ngOnInit() {
this.service.fetchSolutionByName("DEFECT_MANAGEMENT").subscribe(data =>{
this.url = data["solutionURL"];
});
}
}
AppRoutingModule.ts:
const routes: Routes = [
{
path: "login",
component: LoginComponent
},
{
path: "home",
canActivate: [AuthGuardGuard],
component: HomeComponent
},
{
path: "defects",
component: DefectsManagementComponent
},
{
path: "",
redirectTo: "login",
pathMatch: "full"
},
{
path: "**",
redirectTo: "login",
pathMatch: "full"
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule
你应该在 src 周围使用方括号将 url 的值绑定到它,否则你将字符串“url”分配给 src。还可以在 iframe 上使用 ngIf 以仅在填充 url 时显示它。然后您需要清理 url。在