如何重新加载当前页面? [英] How to reload current page?

查看:74
本文介绍了如何重新加载当前页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

来重新加载"当前页面

 私有路由:ActivatedRoute;reload(){this.router.navigate(["/admin/user/edit/" + this.user.id]);} 

基本上,它重定向到当前页面.例如,当前页面是

解决方案

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

  load(val){如果(val == this.router.url){this.spinnerService.show();this.router.routeReuseStrategy.shouldReuseRoute = function(){返回false;};}} 

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

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

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]);
}

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.

but it seems the angular won't redirect/reload the same page with the router.navigate

How I should reload a current page?

Edit:

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.

解决方案

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;
  };

这篇关于如何重新加载当前页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆