Reputation: 154
I want to navigate to a component then refresh the window when clicking on switch() button.
I have tried:
switch() {
this.router.navigateByUrl("/layouts");
window.location.reload();
}
but it is not working as expected, it is only reloading the page without navigate.
Upvotes: 2
Views: 181
Reputation: 1781
navigateByUrl is asynchronous so window.location.reload() is getting called before it returns causing the page to reload before navigating.
navigateByUrl returns a promise so you can do:
this.router.navigateByUrl("/layouts").then(() => {
window.location.reload();
});
Upvotes: 1