我的UI上有两个页面,我想在HTTP响应的基础上重定向用户。PFB代码。
{
"routerName": this.routerName,
"serviceId" : this.serviceId,
"serviceType" : ILL
}现在我的servicetype是ILL,然后我想将页面定向到ILL页面,当值服务类型是GVPN时,我想将它定向到GVPN页面。PFB routerModule
RouterModule.forRoot([
{ path: 'ill' , component: IpIllComponent }, // Want to go to this page when service type is ILL
{ path: 'gvpn' , component: IpGvpnComponent } // Want to go to this page when service type is GVPN
])请在这方面帮帮我。
发布于 2018-06-27 15:08:07
您需要在您的类中插入路由器,然后使用它进行导航:
constructor(private router: Router) {}
const path = response.serviceType === 'ILL'? 'ill' : 'gvpn';
this.router.navigate([path]) 发布于 2018-06-27 15:08:36
constructor(private router: Router, private http: HttpClient) {}
RouteByServiceResponse() {
this.http.get(<url>).subscribe(response =>
if ( response.serviceType === 'ILL' )
{
this.router.navigateByUrl('/ill');
} else if ( response.serviceType === 'GVPN' ) {
this.router.navigateByUrl('/gvpn');
}
});
}发布于 2018-06-27 15:09:38
在运行时,您可以检查服务类型,然后使用router.navigate导航到所需的页面。
if (serviceType === 'ILL')
this.router.navigate(['/ill'])
else
this.router.navigate(['/gvpn']);https://stackoverflow.com/questions/51056401
复制相似问题