angular2和嵌套的子路由

时间:2017-03-25 06:43:26

标签: angular angular2-routing

WOW angular2 - 嵌套路由非常难。

我有这条显示此页面的路线:

 http://localhost:4200/#/dashboard(content:topline)

 <button (click)="onClick('top')">top</button>
 <router-outlet name="toplineul"></router-outlet>

这是路由:

{ path: 'topline',component: ToplineComponent, canActivate: [AuthGuard], outlet:'content', children: [
      { path: 'top',component: TopComponent, canActivate: [AuthGuard], outlet:'toplineul'}
  ]}

如果我点击热线页面上的按钮:

 onClick(event){

       if (event=='top'){
          this.router.navigateByUrl('/dashboard(content:topline//toplineul:top)');
       }
  }

这是我得到的错误:

EXCEPTION: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'top'
Error: Cannot match any routes. URL Segment: 'top'
    at ApplyRedirects.noMatchError (http://localhost:4200/main.bundle.js:133966:16)
    at CatchSubscriber.selector (http://localhost:4200/main.bundle.js:133935:29)
    at CatchSubscriber.error (http://localhost:4200/main.bundle.js:72121:31)
    at MapSubscriber.Subscriber._error (http://localhost:4200/main.bundle.js:484:26)
    at MapSubscriber.Subscriber.error (http://localhost:4200/main.bundle.js:458:18)
    at MapSubscriber.Subscriber._error (http://localhost:4200/main.bundle.js:484:26)
    at MapSubscriber.Subscriber.error (http://localhost:4200/main.bundle.js:458:18)
    at MapSubscriber.Subscriber._error (http://localhost:4200/main.bundle.js:484:26)
    at MapSubscriber.Subscriber.error (http://localhost:4200/main.bundle.js:458:18)
    at LastSubscriber.Subscriber._error (http://localhost:4200/main.bundle.js:484:26)

1 个答案:

答案 0 :(得分:0)

你的错误

  1. 您的父母出口有未公开的支架。

    if (event=='top'){
          this.router.navigateByUrl('/dashboard(content:topline)//top/topline');
       }