主路由器插座内的辅助路由器插座不起作用

时间:2018-12-21 14:22:50

标签: angular router-outlet

我的路由器插座具有以下配置。备用路由器出口包含在主要路由器中。当我尝试使用routerLink显示roster.component.html时,它引发以下错误。我尝试了许多不同的配置,但我不明白为什么它不起作用。

  

错误错误:“ [对象对象]” resolvePromise   http://localhost:4200/polyfills.js:3159:31 resolvePromise   http://localhost:4200/polyfills.js:3116:17 scheduleResolveOrReject   http://localhost:4200/polyfills.js:3218:17 invokeTask   http://localhost:4200/polyfills.js:2766:17 onInvokeTask   http://localhost:4200/vendor.js:73499:24 invokeTask   http://localhost:4200/polyfills.js:2765:17 runTask   http://localhost:4200/polyfills.js:2533:28 raineMicroTaskQueue   http://localhost:4200/polyfills.js:2940:25 invokeTask   http://localhost:4200/polyfills.js:2845:21 invokeTask   http://localhost:4200/polyfills.js:3885:9 globalZoneAwareCallback   http://localhost:4200/polyfills.js:3911:17 core.js:12501

app.module.ts

import { RouterModule, Routes } from '@angular/router';
const appRoutes: Routes = [

  {path: '', component: ProfileComponent},
    {path: 'roster', component: RosterComponent, outlet: 'basis'},

  /*
  {path: '', component: ProfileComponent,children: [
    {path: 'roster', component: RosterComponent, outlet: 'basis'},
  ]}
*/
]
@NgModule({
  declarations: [
    AppComponent,
    MainViewComponent,
    ProfileComponent,
    RosterComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    RouterModule.forRoot(appRoutes),
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

main-view.component.html

  <router-outlet></router-outlet>

profile.component.html

<a [routerLink]="[{ outlets:{ primery:['],basis: ['roster'] } }]">GO</a>
 <router-outlet name="basis"></router-outlet>

2 个答案:

答案 0 :(得分:1)

您似乎有一些错别字,请尝试以下操作:

<a [routerLink]="[{ outlets: { primary: [''],basis: ['roster'] } }]">
    Go
</a>

答案 1 :(得分:0)

路由器配置:

{ path: '', component: ProfileComponent,
    children: [
      { path: 'roster', component: RosterComponent, },
    ]
  }

app.component.html或main-view.component.html

<a routerLink="/roster">Go</a>

profile.component.html

<router-outlet></router-outlet>
相关问题