在我当前 Angular 7 应用程序的场景中,如果网络停止,我将导航用户到连接丢失的组件。我正在用skipLocationChange:true
标志做这个,如下所示
this.router.navigate(['/connection-lost'], {skipLocationChange: true});
现在,如果网络开始工作。我想通过单击 中的重新加载按钮重新加载上一页ConnectionLostComponent
。
我试过了router.navigate([router.url])
,但router.url
给出的 URL/connection-lost
不是地址栏中显示的
例如,如果用户在地址页面('/addresses'),并且连接丢失。然后用户被导航到ConnectionLostComponent
相同的 URL('/addresses')。现在如果用户点击重新加载按钮,那么它应该加载地址页面
我该怎么做?
一个解决方案,我发现是使用navigateByUrl
的方法Router
。
喜欢 :
this.router.navigateByUrl(this.location.path(true));
这里location
from ('@angular/common') 给出了地址栏中显示的确切路径。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句