如何在 Angular 7,8 中重新加载整个页面而不刷新?

6
我正在使用 Angular 8,希望在相同的 URL 上刷新组件而不需要刷新整个页面。我尝试使用 router.navigate,但对我无效。我尝试过 location.reload 和 window.location.reload,但时间太长且会刷新整个页面。以下是我的代码:
this.snackBar.open('Data Updated Successfully', 'Undo', {
        duration: 5000,
      });
      this.router.navigate(['/get_customer_details/'+this.customer_details_id]);
      console.log(this.customer_details_id);
      this.ngOnInit();
1个回答

10

默认情况下,Angular的RouteReuseStrategy为true。你需要将它修改为false。

在你的构造函数中使用以下代码。

constructor(private route: ActivatedRoute, private router: Router) {
    this.router.routeReuseStrategy.shouldReuseRoute = () => false;
  }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接