angularroutescomponentsrefresh

How to Refresh a Component in Angular


I am working on an Angular project. I'm struggling with refresh action in a component.

I would like to refresh the router's components on button click. I have refresh button when I click on it the component/router need to be refresh.

I tried window.location.reload() and location.reload() these two are not suitable for my need. Please help if anyone aware of it.


Solution

  • After some research and modifying my code as below, the script worked for me. I just added the condition:

    this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() => {
        this.router.navigate(['Your actualComponent']);
    });