How to router.navigate to same route in Angular 4 and catch the same event?

前端 未结 4 503
情深已故
情深已故 2021-01-02 08:35

Okay, I have two use cases for my question here:

  1. I\'m working on an application which has a /en/register route. It all works good when I\'m at t

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 09:17

    When I needed to "reload" the current component's constructor and ngOnInit functions, the only solution I found was kind of a workaround:

    I used the fact that "this.router.navigate" returns a promise. So I navigated somewhere else, and returned. It's a bit ugly but it works and the UI is not affected:

    this.router.navigate(..[somewhere else]..)
        .then(()=>{this.router.navigate(..back..)})
    

    Hope it helps.

提交回复
热议问题