Angular 2路由器。子路线在第二次没有激活
问题描述:
我有Angular 4.1.3应用程序与Angular 2路由器。我用下面的路线配置:Angular 2路由器。子路线在第二次没有激活
export let ARTICLE_ROUTES: Routes = [
{
path: 'article/:id', component: ArticleComponent,
children: [
{path: '', component: ArticleContentComponent, pathMatch: 'full'},
{path: ':detailId', component: ArticleContentComponent}
]
}
];
这里是在ArticleComponent部分之间如何我浏览:
<a [routerLink]="[section.id]">{{section.title}}</a>
当我点击一些链接部分的ArticleContentComponent被激活并重新呈现。当我点击另一个链接ArticleContentComponent未激活。即使它的构造函数没有被调用。在控制台中没有可见的错误。
我试着使用编程的导航,但它也没有为第二次工作:
this.router.navigate([sectionId], { relativeTo: this.route});
请咨询。
答
您需要申请的activatedRoute parmeters这样
this._activatedRoute.params.subscribe(p => this.loadMovie(p["id"]));
经过深入调查研究,我发现,只有检测路由变化的方式是订阅路线PARAMS。即使ArticleContentComponent未被重载,路由也会推送新的值:this.route.params.map(param => param.detailId).subscribe(item => this.handleSubArticle(item)); – Sergey