本文介绍了无法重新加载/刷新活动路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新到了新的 RC3 和 Router3alpha,似乎有些事情发生了变化.

I have recently updated to the new RC3 and Router3alpha and it seems some things have changed.

我注意到单击活动路由的链接不再导致重新加载组件.我如何使用新的 router3 实现这种行为?

I noticed that a click on the link of an active route does no longer result in the component to be reloaded. How do I achieve this behaviour with the new router3?

我的链接看起来像

<a [routerLink]="['/link1']">Link1</a>

为了测试,我只是在 ngOnInit 中使用了一个随机数:

And to test I simply used a random number in ngOnInit:

export class LinkoneComponent implements OnInit
{

    public foo: number;
    constructor() {}

    ngOnInit()
    {
        this.foo = Math.floor(Math.random() * 100) + 1;
    }

}

在路由之间切换时它工作得很好,但单击当前活动的路由不会导致重新加载组件.

It works just fine when switiching between routes, but a click on the currently active route does not result in a reload of the component.

推荐答案

目前不支持.如果仅参数值更改但路由保持不变,则不会重新创建组件.

This is currently not supported. If only parameter values change but the route stays the same the component is not re-created.

另见https://github.com/angular/angular/issues/9811

您可以订阅 params 以在 params 更改时收到通知以重新初始化组件实例.

You can subscribe to params to get notified when the params change to re-initialize the component instance.

另见https://stackoverflow.com/a/38560010/217408

这篇关于无法重新加载/刷新活动路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:41