Angular 6-如何重新加载当前页面?

问题描述:

我有一个用于编辑用户的页面,里面有一些子组件.每个子组件都可以更改其父组件或对其产生某些影响.

I have a page for editing user, it has some children components inside. Each children components can change or doing some effect to its parent component.

因此,我没有将更改发送给父对象并更新了某些字段,而是使用

So instead of emitting the changes to parent and updating some fields, I did a "reload" of the current page with

private route: ActivatedRoute;

reload(){
    this.router.navigate(["/admin/user/edit/"+this.user.id]);
}

基本上,它重定向到当前页面.例如,当前页面是 http://web.info/admin/user/edit/9 它将被重定向希望此页面中的所有数据都重新加载了最新数据.

Basically, it redirects to the current page. For example, the current page is http://web.info/admin/user/edit/9 it will be redirected to this page with the hope all the data inside that page reloaded with the newest data.

,但似乎不会用router.navigate

我应该如何重新加载当前页面?

How I should reload a current page?

这是为什么我需要重新加载页面而不是手动更新当前页面上的数据的原因.我需要在其他组件"上进行更新,当我执行更新时,它将向历史记录"组件中添加一些内容.我需要同时刷新用户组件"和历史记录"组件,因为这两个组件都受到其他组件"中更改的影响.

Here is the reason why I need to reload the page instead of manually updating the data on the current page. I need to do updates on Other Component, when I did the update it will add something to History Component. I need to refresh the User Component and History Component together since both components affected by the changes in Other Component.

它将100%有效.以下代码行负责在我的项目中重新加载页面.

It will work 100%. The following lines of code are responsible for page reload in my project.

load(val) {
if (val == this.router.url) {
  this.spinnerService.show();
  this.router.routeReuseStrategy.shouldReuseRoute = function () {
    return false;
  };
 }
}

只需在代码中使用以下部分即可.

Just use the following part in your code.

this.router.routeReuseStrategy.shouldReuseRoute = function () {
    return false;
  };