所以我想在导航到特定路线后重新加载应用程序..
我使用router.navigate导航到基于用户角色的特定路由,并且工作正常但是我必须在路由后重新加载页面,如果来自登录页面(不是每次用户打开该特定路由) - 并且重新加载这里是更新页面语言取决于用户的语言
所以我试图做的是
else if(this.sp.role === 'Admin') {
console.log('ooo')
this.router.navigate(['/admin/dashboard']);
this.window.location.reload();
但是重新加载登录页面
您可以做的是将重载逻辑转移到需要重新加载的实际组件。您可以订阅NavigationEnd事件,然后检查您来自的路线,例如
this.router.events
.pipe(
filter(value => value instanceof NavigationEnd),
)
.subscribe(event => {
if (event.url === 'http://mypreviousUrl.com') {
this.window.location.reload();
}
});
简单
this.router.navigate(['path/to'])
.then(() => {
window.location.reload();
});