【问题标题】:window.location.reload() only refresh the home page, Why it does not refresh the other pages specifically using angular?window.location.reload() 只刷新主页,为什么不刷新专门使用angular的其他页面?
【发布时间】:2021-11-04 06:07:33
【问题描述】:

当我从主页导航到菜单页面时,导航后菜单页面应该会自动刷新一次,但是当我使用以下代码时,它会刷新主页然后导航到菜单页面,其中菜单页面不会自动刷新

1)第一种方法:

this.router.navigate([`locations/${locationId}/menu`])
      .then(() => {
        window.location.reload();
      });

2)第二种方法:

this.router.navigate([`locations/${locationId}/menu`])
      .then(() => {
        location.assign(locations/locationId/menu);
      });

【问题讨论】:

  • 你能详细说明这两种方法的用途吗?
  • 这是我从主页导航后尝试刷新菜单页面的两种方法。
  • 您可以将重新加载逻辑转移到需要重新加载的实际组件。您可以订阅 NavigationEnd 事件,然后查看您要来的路线
  • 我已经在菜单页面的实际组件中给出了重新加载逻辑。
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: javascript angular routes google-chrome-devtools refresh


【解决方案1】:

我不确定您要达到什么目的,但是如果您想从主页重新加载菜单页面,那么您应该进行如下更改:

this.router.navigate([]).then(_result => {
    window.location.replace(`locations/${locationId}/menu`);
});

【讨论】:

  • 谢谢@Devang Patel
猜你喜欢
  • 2020-10-08
  • 1970-01-01
  • 1970-01-01
  • 2015-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多