-1

Reload or refresh the current page when a function isRefresh() is called.

Surbhi
  • 39
  • 1
  • 7
  • try `window.location.reload` – Saurabh Agrawal May 07 '19 at 07:28
  • It redirects to the homepage.I want to redirect it to the current page. – Surbhi May 07 '19 at 07:29
  • 3
    Possible duplicate of [How to Refresh a Component in Angular](https://stackoverflow.com/questions/47813927/how-to-refresh-a-component-in-angular) – wentjun May 07 '19 at 07:29
  • then you should use component refresh. – Saurabh Agrawal May 07 '19 at 07:30
  • It won't redirect if you use path location strategy. – MonkeyScript May 07 '19 at 07:31
  • This actually gives me the cuurent page + the homepage together.it is redirected to the current page ,and if we scroll down we see the homepage screen as well! – Surbhi May 07 '19 at 07:31
  • @SaurabhAgrawal can u please explain refresh component.Dont have much idea about it. – Surbhi May 07 '19 at 07:34
  • 2
    Why would a reload redirect to homepage? you have got guards for the current route? – Ashish Ranjan May 07 '19 at 07:41
  • 1
    Hi and welcome to Stack Overflow, please take a time to go through the [welcome tour](https://stackoverflow.com/tour) to know your way around here (and also to earn your first badge), read how to create a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and also check [How to Ask Good Questions](https://stackoverflow.com/help/how-to-ask) so you increase your chances to get feedback and useful answers. – Jessica Rodriguez May 07 '19 at 08:30

2 Answers2

2

This will do,

window.location.reload()
MonkeyScript
  • 4,776
  • 1
  • 11
  • 28
  • It doesn't meet the requirement. Redirects to homepage,not current page. – Surbhi May 07 '19 at 07:37
  • It's not supposed to redirect unless you are not doing routes and only using a single page actually. Can you provide a stackblitz demo? – MonkeyScript May 07 '19 at 07:56
2

This isn't the right way to usually approach things, but as an answer to your problem:

constructor(private router: Router){};
// Custom refresh code
reloadWindow() {
    this.router.navigateByUrl(`/`).then(
            () => {this.router.navigateByUrl(this.router.url);});
}
crooksey
  • 8,521
  • 6
  • 30
  • 52