Angular 2路由到同一路由 [英] Angular 2 routing to the same route

查看:116
本文介绍了Angular 2路由到同一路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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)

推荐答案

默认情况下,如果routeparams没有更改,

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

Router.renavigate();

Router.renavigate();

this.router.navigate('RouteName', this.routeParams.params)

重新演习.

这篇关于Angular 2路由到同一路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆