【问题标题】:Nested Routing Links Angular 4嵌套路由链接Angular 4
【发布时间】:2017-08-11 14:29:07
【问题描述】:

这是我的当前设置

 - 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)

所以,现在如果我在 service1.componenet 中使用 router.navigateByUrl,我将不得不这样做:

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

我将不得不继续嵌套路由模块,所以以后知道路由的 “父母” 可能是个问题,我想知道是否有更有效的解决方案 而不是复制整个路线,例如:

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

其中的 parentRoute 是嵌套路由的汇编。

【问题讨论】:

    标签: angular routing angular2-routing


    【解决方案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
        });
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-13
      相关资源
      最近更新 更多