Angular 5 - 当我使用RouteReuseStrategy时如何重新加载当前数据

问题描述 投票:0回答:1

我正在使用RouteReuseStrategy来控制路由快照缓存,它可以很好地从我的搜索组件转到另一个组件,当我点击“返回”时,我有旧的(搜索)组件。问题是,如果我转到另一个组件并编辑某个值并返回搜索,那么该值仍然是旧的而不是新的。我如何使用当前数据?

谢谢。

angular angular5
1个回答
1
投票

告诉路由器如何对组件进行操作。

首先告诉他在你的组件中传播路由事件

this.router.onSameUrlNavigation = 'reload';

接下来,告诉他在路由事件上做一些事情,特别是在最后一个事件上

this.router.events.subscribe(event => {
  if (!(event instanceof NavigationEnd)) { return; }
  // Do what you need to do here, for instance : 
  ngOnInit();
});
© www.soinside.com 2019 - 2024. All rights reserved.