How to reload a page in Angular 8 the proper way

前端 未结 6 1876
迷失自我
迷失自我 2021-01-07 15:17

NB. I\'ve got a set of resulting from googling but, as I explain at the end, I sense that they aren\'t reliable, due to diversity.

I have two utility method

6条回答
  •  抹茶落季
    2021-01-07 15:26

    ok this next example works for me without reload the page:

    on router component you have tu add 'onSameUrlNavigation' router.component:

    @NgModule({
      imports: [RouterModule.forRoot(routes, { onSameUrlNavigation: 'reload' })],
      exports: [RouterModule],
    })
    

    now component you want reload

    constructor(private router: Router){
      this.router.routeReuseStrategy.shouldReuseRoute = () => {
        return false;
      };
    }
    
    someFunction(){
      this.router.navigateByUrl('/route');
    }
    

提交回复
热议问题