【问题标题】:Angular 5 page reloadAngular 5页面重新加载
【发布时间】:2018-08-02 00:51:41
【问题描述】:

有人能帮帮我吗?我使用 Angular 5。当我导航到 this.router.navigate(['somePath']); 之类的路线时,我在浏览器中的 url 更改为 basicUrl/somePath。一切正常,直到页面在浏览器中重新加载。之后我看到了我的组件(没有导航栏和其他东西,只有我的组件 html)。我该如何改善这种行为?现在我的每个组件都有

ngOnInit() {
    this.location.replaceState('/');
}

替换浏览器网址。但我不喜欢这种解决方案。

【问题讨论】:

  • 看看HashLocationStrategy
  • 请发布您的主要路由文件。

标签: angular navigation reload


【解决方案1】:

按钮点击事件中的window.location.reload

<button type="button" mat-raised-button color="warn" onclick="window.location.reload();">

【讨论】:

    【解决方案2】:

    你应该相对导航:

    import { Router, ActivatedRoute } from '@angular/router';
    this.router.navigate(['somePath', ], {relativeTo: this.activatedRoute});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 2016-04-10
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 2021-05-15
      • 2021-01-23
      相关资源
      最近更新 更多