如何防止组件在 angular2 中的查询参数更改时再次加载?
How to prevent a component to load again on query parameter change in angular2?
this.router.navigate(['CurrentComponent', {id: this._id, param1: value}]);
以上代码更新了当前url的查询参数。在 url 更改后,组件将再次加载。
如何防止重新加载组件并仅更新查询参数?
将方法 routerCanReuse
添加到您的组件并 return true
routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction) { return true; }
另见 CanReuse
this.router.navigate(['CurrentComponent', {id: this._id, param1: value}]);
以上代码更新了当前url的查询参数。在 url 更改后,组件将再次加载。 如何防止重新加载组件并仅更新查询参数?
将方法 routerCanReuse
添加到您的组件并 return true
routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction) { return true; }
另见 CanReuse