我正在使用RouteReuseStrategy来控制路由快照缓存,它可以很好地从我的搜索组件转到另一个组件,当我点击“返回”时,我有旧的(搜索)组件。问题是,如果我转到另一个组件并编辑某个值并返回搜索,那么该值仍然是旧的而不是新的。我如何使用当前数据?
谢谢。
告诉路由器如何对组件进行操作。
首先告诉他在你的组件中传播路由事件
this.router.onSameUrlNavigation = 'reload';
接下来,告诉他在路由事件上做一些事情,特别是在最后一个事件上
this.router.events.subscribe(event => {
if (!(event instanceof NavigationEnd)) { return; }
// Do what you need to do here, for instance :
ngOnInit();
});