2017-08-11 114 views
0

这是我当前设置嵌套路由链接角4

- app (Folder) 
    - app-routing.module.ts (File) 
    - client (Folder) 
     - client-routing.module.ts (File) 
      - service (Folder) 
       - service-routing.module.ts (File) 
       - service1.componenent.ts (File) 
       - service2.componenent.ts (File) 

所以,现在如果我使用router.navigateByUrlservice1.componenet我必须做这样的:

this.router.navigateByUrl('/client/service2'); 

我必须保持嵌套路由模块,因此知道“父母”的扣肉 TE以后可能是一个问题,我想知道是否有一个更有效的解决方案而不是复制整条路线,是这样的:

this.router.navigateByUrl(parentRoute + '/service2'); 

凡parentRoute它的嵌套路线的汇编。

回答

1

您可以尝试在service1component中使用ActivatedRoute。 类似这样的:

import { Router, ActivatedRoute } from '@angular/router'; 

@Component({ 
... 
}) 
export class Service1Component { 
constructor(
    private _router:Router, 
    private _route: ActivatedRoute 
){} 

... 

    navigate(){ 
    this._router.navigate(['./service2'],{ 
     relativeTo: this._route 
    }); 
    } 
}