0

我是否可以router-outlet在除AppComponent? 因为目前当我这样做并尝试使用它激活它时,[routlerLink]我在控制台中收到一个错误,抱怨它找不到名为 popup 的插座。如果我把它移回AppComponent它的工作原理!

所以这是我的项目的结构:

app/
├──auth/
│  └──login/
│     └──login.component.ts/html/scss
├──landing/
│  ├──landing.module.ts
│  ├──landing.routing.ts
│  └──landing.component.ts/html/scss
├──app.module.ts
├──app.routing.ts
└──app.component.ts/html/scss

这是相关代码(landing.routing/landing.component.html):

const routes: Routes = [{
  path: '',
  component: LandingComponent,
  children: [{
    path: 'login',
    component: LoginComponent,
    outlet: 'popup'
  }]
}];
<p>
  <a [routerLink]="[{ outlets: { popup: ['login'] } }]">Login</a>
</p>
<router-outlet></router-outlet>
<router-outlet name="popup"></router-outlet>

...最后是 app.routing.ts 路由:

const routes: Routes = [
    { path: 'landing', loadChildren: 'app/landing/landing.module#LandingModule' },
    { path: '', component: HomepageComponent, canActivate: [AuthGuard] },
    { path: '**', component: NotFoundComponent }
];

4

0 回答 0