【发布时间】:2020-11-30 11:53:57
【问题描述】:
我想导航到一个组件,然后在单击 switch() 按钮时刷新窗口。
我试过了:
switch() {
this.router.navigateByUrl("/layouts");
window.location.reload();
}
但它没有按预期工作,它只是重新加载页面而不导航。
【问题讨论】:
标签: angular routes state angular8
我想导航到一个组件,然后在单击 switch() 按钮时刷新窗口。
我试过了:
switch() {
this.router.navigateByUrl("/layouts");
window.location.reload();
}
但它没有按预期工作,它只是重新加载页面而不导航。
【问题讨论】:
标签: angular routes state angular8
navigateByUrl 是异步的,因此 window.location.reload() 在返回之前被调用,导致页面在导航之前重新加载。
navigateByUrl 返回一个承诺,所以你可以这样做:
this.router.navigateByUrl("/layouts").then(() => {
window.location.reload();
});
【讨论】: