当我从服务器得到一些响应时,我想重定向到另一个页面。(这个过程太慢了,需要将近 60 秒才能从服务器获得响应)。同时,我会展示一些微调的东西,当我得到响应时,我会重定向到另一个页面。看起来很简单?
是的,但问题是,当我收到响应时,页面不会自动重定向。它停留在同一页面上,现在,如果我点击页面上的任何地方,它会重定向到另一个页面,有点奇怪的情况。
this.optimizationService
.runOptimization(this.runOptimizationModel)
.subscribe(optimizationResult => { // this is the first service which send request to server.
this.optimizationService.notificationEvent.subscribe(eventData => {
console.log(eventData); // this is another external service for notifications in which, when I will get the response, I want to redirect to another page.
if (eventData && eventData.length) {
this._router.navigate([this.optimizationResultScreenURL, 'e1517589-905e-485b-b7ee-7bc6521dcc93']); // This is url rerouting. If I cut and paste this line after first service subscription, it is working fine.
}
});
});
是否出现这种情况,因为我们在 60 秒后收到第二个服务的响应。这是一个有点奇怪的场景,但它正在发生。这60秒是小人吗。
这最终解决了我的问题。
返回 this.zone.run(() => this.router.navigate(['/path/to/route']));
问题是,路由器导航在外部请求后不会激活 onInit。第二个订阅正在使用外部通知请求。
参考:https : //github.com/angular/angular/issues/20112#issuecomment-398060545
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句