Search code examples
javascriptangularangular7angular-routingangular7-router

Not able to redirect the route after windows reload


I have two pages and those are role-list and role-details. There is requirement that depends on role that i need to hide the menu options after save button click. This i am able to fulfill with the below code

windows.location.reload();

after reload i need to navigate to the different page.. for that purpose i am using below code.

if(this.menuHide == "true"){     
   window.location.reload();
   this.router.navigateByUrl('/', {skipLocationChange: true}).then(()=>
   this.router.navigate(['role-list']));
} 

also tried with these options as well

this.router.navigate(['/role-list']));
this.router.navigateByUrl('/role-list'); 

the code below reload method is not executing that means it is not redirecting to role-list page. I am using angular 7 version.

Could any one please suggest any ideas on how to navigate to other page that would be grateful to me, many thanks in advance.


Solution

  • I have solved this issue by using below code

      if(this.menuHide == "true"){
          this.router.navigate(['/role-list']).then(()=>{
               window.location.reload();
           });
        } 
    

    It is working perfectly fine .. Thank you all for your valuable suggestions.