0

I have a switch to shop function which is controlled by a header component and displays a dashboard for that venue.

In that header component, I navigate to dashboard route, even if I already in that route.

this.router.navigate(['/venues', this.currentVenue._id, 'dashboard']);

But it doesn't trigger ngOnInit hook again so my view is not reloaded.

What is the correct workaround for such case?

4

1 回答 1

2

您需要重新加载视图吗?或者只是重新获取一些数据?

如果只需要根据路由参数重新获取数据,可以这样做:

ngOnInit(): void {
    this.route.params.subscribe(
        params => {
            const id = +params['id'];
            this.getMovie(id);   // <- Or whatever you need to do here
        }
    );
}

在 ngOnInit 中,此代码订阅路由参数。因此,每次参数更改时,即使视图没有更改/重新加载,更改也会作为订阅的一部分被拾取并执行相关的回调。

于 2017-10-18T21:22:36.340 回答