Javascript 如何在Angular 2中重新加载组件的内容?
在运行时的某一时刻,我的url看起来像Javascript 如何在Angular 2中重新加载组件的内容?,javascript,angular,components,angular2-routing,Javascript,Angular,Components,Angular2 Routing,在运行时的某一时刻,我的url看起来像 http://localhost:4200/personal/51c50594-a95c-4a18-ac7b-b0521d67af96 我想转到一个只有不同GUID和不同内容的页面 http://localhost:4200/personal/{otherGuid} 这不起作用: this.router.navigate(['/personal',new_ guid]); 如何在angular 2中实现这一点?您可以导航到中间路线/personal,
http://localhost:4200/personal/51c50594-a95c-4a18-ac7b-b0521d67af96
我想转到一个只有不同GUID
和不同内容的页面
http://localhost:4200/personal/{otherGuid}
这不起作用:
this.router.navigate(['/personal',new_ guid]);
如何在angular 2中实现这一点?您可以导航到中间路线
/personal
,在该页面中,您可以获取参数,并使用switch case再次根据参数导航到其他路线。在后一部分中,如果您不想更改url栏中显示的路由,可以使用以下代码进行更改
this.router.navigate(['/view'], { skipLocationChange: true });
skipLocationChange:true
导航时不会将新状态推入历史记录
为了便于参考,您可以在下面查看
....
this.router.navigate(['personal', id]);
....
constructor(route: ActivatedRoute, router: Router){
this.route.params.subscribe(param => {
// this will be fired when you change the guid,
// use the new param to reload component..
})
}
检查这个 你试过相对导航吗<代码>this.router.navigate([new_guid],{relativeTo:this.route})代码>这可能会有帮助:@user7552,它不工作。只有url被更改。这对你有帮助吗:@Alexandru IonutMihai你只想用它的内容导航到新页面,对吧,对不起,但我不能理解这个问题,你能告诉我吗?如果对meI来说,什么对他不起作用,是内容没有更改,但url是。如果是这种情况,那么提供的@Vega链接可能会解决这个问题。组件已渲染,只有
参数
已更改。因此,您只需订阅它并相应地更改它,就像该链接中显示的答案一样。是的,这也是一个解决方案:。谢谢。