0
我遇到问题了解如何正确地在路由中执行路由。我想什么来实现:Angular 2(rc5)路由器 - 侧栏导航(子路由)
App
-Contacts (view)
-News (view)
SidebarNavigation (persistent throught news)
-InfoOne (child-view of news)
-InfoTwo (child-view of news)
news.component.html
<div class="sidebar-navigation>
<a routerLink="/news/info-one" routerLinkActive="active">Info one</a>
<a routerLink="/news/info-two" routerLinkActive="active">Info two</a>
</div>
<router-outlet></router-outlet>
现在,我遇到的问题是,每当我点击info-one
/info-two
侧边导航栏中消失。如何分辨角度以显示子女<router-outlet></router-outlet>
内的子女观点,而不是主要的<router-outlet></router-outlet>
?
我已经创建了一个叉plunker出官方教程。 看看:app/news.component.ts
和app/app.routing.ts
更多的代码:
app.routing.ts
:
import { Routes, RouterModule } from '@angular/router';
import { ContactComponent } from './contact.component';
import { NewsComponent, InfoOneComponent, InfoTwoComponent } from './news.component';
const appRoutes: Routes = [
{
path: '',
redirectTo: '/news',
pathMatch: 'full'
},
{
path: 'contact',
component: ContactComponent
},
{
path: 'news',
component: NewsComponent
},
{
path: 'news/info-one',
component: InfoOneComponent
},
{
path: 'news/info-two',
component: InfoTwoComponent
}
];
export const routing = RouterModule.forRoot(appRoutes);
感谢
'children'就是我一直在寻找的东西:)非常感谢,虽然看起来你已经搞砸了一下,它只显示信息一。我已经更正了它,如果可以的话,请在您的帖子中更新以备将来参考。 [updated-plunker](http://plnkr.co/edit/g4UTf82IBtZh6DmVoYLf?p=preview)另外,你不需要额外的东西:编号的东西。 – Baki
感谢在答案中添加了更新的plunker,我实际上正在尝试一些东西并没有意识到,我正在更新的答案中添加了plunker。 –
对我有帮助,谢谢 – Kamruzzaman