【问题标题】:secondary router outlet inside primary router outlet not working主路由器插座内的辅助路由器插座不工作
【发布时间】:2018-12-21 14:22:49
【问题描述】:

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

错误错误:“[object Object]”resolvePromise http://localhost:4200/polyfills.js:3159:31resolvePromise http://localhost:4200/polyfills.js:3116:17 scheduleResolveOrReject http://localhost:4200/polyfills.js:3218:17invokeTask http://localhost:4200/polyfills.js:2766:17onInvokeTask http://localhost:4200/vendor.js:73499:24invokeTask http://localhost:4200/polyfills.js:2765:17runTask http://localhost:4200/polyfills.js:2533:28drainMicroTaskQueue http://localhost:4200/polyfills.js:2940:25invokeTask http://localhost:4200/polyfills.js:2845:21invokeTask http://localhost:4200/polyfills.js:3885:9globalZoneAwareCallback http://localhost:4200/polyfills.js:3911:17core.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 { }

ma​​in-view.component.html

  <router-outlet></router-outlet>

profile.component.html

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

【问题讨论】:

    标签: angular router-outlet


    【解决方案1】:

    你好像有错别字,试试这个:

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

    【讨论】:

      【解决方案2】:

      路由器配置:

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

      【讨论】:

        猜你喜欢
        • 2017-02-15
        • 2021-03-13
        • 2018-07-28
        • 2017-04-29
        • 1970-01-01
        • 2020-07-24
        • 2016-12-30
        • 2017-02-21
        相关资源
        最近更新 更多