1

I know angular is a SPA, but I am just wondering is it possible to reload the page if routerlink does not change. For example, I have a sidemenu navbar with Dashboard button to navigate to dashboard view

[routerLink]="['/merchant/', {outlets: {'page': ['Dashboard']}}]"

And after I navigated to Dashboard, the Dashboard button is not clickable, is there any way I could re-click this dashboard button?

The reason I want to do that is on the dashboard component, I have main view which is the dashboard, contains few md-card. By clicking each md-card, I will do *ngIf to only display the full details of this card. I do have a goBack() button to go back to the dashboard view.

But I also want to click the dashboard button in the sidemenu to navigate back to dashboard page.

Thanks for any help.

Alex
  • 143
  • 10

1 Answers1

3

Try using the following snippet of code. This might help you.

this._router.routeReuseStrategy.shouldReuseRoute = function(){
    return false;
};

this._router.events.subscribe((evt) => {
    if (evt instanceof NavigationEnd) {
        this._router.navigated = false;
        window.scrollTo(0, 0);
    }
});

API Link to Route Reuse Strategy: https://angular.io/api/router/RouteReuseStrategy

Reference: How to reload the current route with the angular 2 router

haMzox
  • 2,073
  • 1
  • 12
  • 25
  • Thank you the solution. It is working, but raised another problem. In the sidemenu, I have md-expansion-panel, after I add those code to ngInit(), click any of the sub item, the expansion-panel will not remain expanded. – Alex Oct 22 '18 at 06:21
  • Yeah that can happen. I think you have to handle it manually then, because we are not encouraged to use route reuse strategy since it can cause your application to malfunction. – haMzox Oct 22 '18 at 06:26
  • Oka, I might need think something else then. Cheers for it. – Alex Oct 22 '18 at 06:40
  • No problem. It will be great if you can mark this answer as correct so that others can take help from this question which you faced :) – haMzox Oct 22 '18 at 07:39