首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在响应角6的基础上定向到页面

如何在响应角6的基础上定向到页面
EN

Stack Overflow用户
提问于 2018-06-27 14:58:12
回答 4查看 256关注 0票数 0

我的UI上有两个页面,我想在HTTP响应的基础上重定向用户。PFB代码。

代码语言:javascript
复制
 {
      "routerName": this.routerName,
      "serviceId" : this.serviceId,
      "serviceType" : ILL
}

现在我的servicetype是ILL,然后我想将页面定向到ILL页面,当值服务类型是GVPN时,我想将它定向到GVPN页面。PFB routerModule

代码语言:javascript
复制
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
    ])

请在这方面帮帮我。

EN

回答 4

Stack Overflow用户

发布于 2018-06-27 15:08:07

您需要在您的类中插入路由器,然后使用它进行导航:

代码语言:javascript
复制
constructor(private router: Router) {}

const path = response.serviceType === 'ILL'? 'ill' : 'gvpn';
this.router.navigate([path]) 

请参阅文档:https://angular.io/guide/router

票数 0
EN

Stack Overflow用户

发布于 2018-06-27 15:08:36

代码语言:javascript
复制
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');
        }
    });
}
票数 0
EN

Stack Overflow用户

发布于 2018-06-27 15:09:38

在运行时,您可以检查服务类型,然后使用router.navigate导航到所需的页面。

代码语言:javascript
复制
if (serviceType === 'ILL')
  this.router.navigate(['/ill'])
else
  this.router.navigate(['/gvpn']);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51056401

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档