angular - Angular 5 - 当我使用 RouteReuseStrategy 时如何重新加载当前数据
问题描述
我正在使用 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();
});