【发布时间】:2018-09-01 10:31:11
【问题描述】:
我正在尝试在路由器内创建子级。但是,我无法在应用程序中呈现子组件。
这是我的代码:
<ul class="nav navbar-nav">
<li class="active"><a routerLink="/portal/home">Início</a></li>
<li><a routerLink="/portal/courses">Cursos</a></li>
<li><a routerLink="">Ferramentas</a></li>
<li><a routerLink="">Central de Ajuda</a></li>
</ul>
<router-outlet name="dash"></router-outlet>
在上面我们可以看到我的部分 html 与路由器插座。
在routing.ts下面:
const routes: Routes = [
{
path: '',
pathMatch: 'full',
redirectTo: 'portal'
},
{
path: 'portal',
component: PortalComponent,
children: [
{
path:'',
pathMatch: 'full',
redirectTo: 'home'
},
{
path: 'home',
component: HomeComponent,
outlet:'dash'
},
{
path: 'courses',
component: CoursesComponent,
outlet:'dash'
}
]
},
{
path: 'profile',
component: ProfileComponent
}
];
这里我们看不到其他组件,因为我正在尝试简化这里的代码。当我尝试点击课程时,错误是:
错误:无法匹配任何路由。 URL 段:门户/课程
我还有另一个页面,我在其中设置了一个路由器插座来处理上述代码。检查:
<main id="main">
<div id="main-content">
<div class="container">
<router-outlet></router-outlet>
</div>
</div>
<aside id="main-chat">
<chat-dialog></chat-dialog>
</aside>
</main>
【问题讨论】: