问题描述
我有Ride
组件,并且在骑行结束时显示了Ride Summary
.
I have Ride
component, and in the end of the ride the Ride Summary
is shown.
正确的摘要中有一个开始另一个旅程"按钮,该按钮重定向到相同的组件Ride
.
The right summary has a button to "Start another ride" which redirects to the same component, Ride
.
[routerLink]="['Ride']"
由于Ride
组件已经是我所在的组件,因此不会刷新,并且Ride Summary
屏幕会一直显示.
Since the Ride
component is already the one i'm in, it's not refreshed and the Ride Summary
screen is keep showing.
在重新导航到Ride
组件时如何重新初始化它? (再次使用ngOnInit方法)
How I can re-init the Ride
component when re-navigating to it? (use again the ngOnInit method)
推荐答案
默认情况下,如果route
和params
没有更改,
Router
不会导航.
Router
doesn't navigate if the route
and params
haven't changed, by default.
要使其导航,您可以定义
To make it navigate you can define
routerCanReuse(nextInstruction: ComponentInstruction,
prevInstruction: ComponentInstruction){
return false;
}
要在其中进行重新调用的内容,然后调用
in your component, that you want to renvaigate to, and call
this.router.navigate('RouteName', this.routeParams.params)
重新演习.
这篇关于Angular 2路由到同一路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!