angular 路由器导航然后重新加载
angular router navigate then reload
所以我想在导航到特定路线后重新加载应用..
我使用 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();
});
简单做
location.href = '/admin/dashboard';
所以我想在导航到特定路线后重新加载应用..
我使用 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();
});
简单做
location.href = '/admin/dashboard';