如何使用 Router 在 ionic 4 中重新加载页面?
How to reload a page in ionic 4 using Router?
我想使用路由器从另一个组件重新加载页面组件。
我厌倦了通过以下解决方法重新加载页面。它正在工作,但效率不高。
this.router.navigateByUrl('/SampleComponent', {skipLocationChange: true}).then(()=>{
this.router.navigate([page]);
});
我们是否有任何其他方法来重新加载页面?
如果您希望在导航到同一页面时重新加载页面 URL 那么您可以在根模块下使用此配置:
@NgModule({
imports: [
...
RouterModule.forRoot(routes, { onSameUrlNavigation: 'reload'})
....
],
declarations: [ ... ],
bootstrap: [ ... ]
})
您无需转到另一个组件并导航回相同组件,只需使用:
this.router.navigate([page]);
您正在使用的 skipLocationChange
将阻止将新的 url 推送到浏览器历史记录,这样如果您按返回键,它就不会走您正在导航的临时路线。
我想使用路由器从另一个组件重新加载页面组件。
我厌倦了通过以下解决方法重新加载页面。它正在工作,但效率不高。
this.router.navigateByUrl('/SampleComponent', {skipLocationChange: true}).then(()=>{
this.router.navigate([page]);
});
我们是否有任何其他方法来重新加载页面?
如果您希望在导航到同一页面时重新加载页面 URL 那么您可以在根模块下使用此配置:
@NgModule({
imports: [
...
RouterModule.forRoot(routes, { onSameUrlNavigation: 'reload'})
....
],
declarations: [ ... ],
bootstrap: [ ... ]
})
您无需转到另一个组件并导航回相同组件,只需使用:
this.router.navigate([page]);
您正在使用的 skipLocationChange
将阻止将新的 url 推送到浏览器历史记录,这样如果您按返回键,它就不会走您正在导航的临时路线。