【发布时间】:2016-09-04 14:20:15
【问题描述】:
我仍在使用 alpha8 路由器。我有 3 条主要路线:
export const appRoutes: RouterConfig = [
{ path: '', component: LandingComponent },
{ path: 'blog', component: BlogComponent },
{ path: 'posts/:id', component: PostComponent },
{ path: 'posts', redirectTo: 'blog' },
{ path: '**', redirectTo: ''}
];
所以我有一个包含精选帖子和链接的组件,它在 BlogComponent 中工作得很好,但是当这个组件在 PostComponent 中时,id 只会更改 url 地址。 这就是该组件中链接的样子
<a [routerLink]="['/posts/'+post.id]">...</a>
所以当我们在localhost:5000/blog 时,它可以很好地路由到localhost:5000/posts/19 f.ex。但是从localhost:5000/posts/19 不会转到localhost:5000/posts/20。它只是改变了 url,contstructor,ngOnInit 不会被执行。我该如何解决这个问题?
【问题讨论】:
标签: angular typescript angular2-routing