![](/img/trans.png)
[英]How to trigger animation when routed to the same page with different URL parameter using Angular in Ionic 5
[英]How do I refresh the page when a user is routed in Ionic 5 using Angular
我在Page B
,当在Page B
执行操作时,我将用户路由到Page A
。 如何刷新Page A
以便我可以获取新数据。 我编写了一个服务来获取我在Page A
的构造函数中调用的数据,如下所示。
A页
Page A
的构造函数
data: any = [];
constructor(
private dataService: DataService,
private route: ActivatedRoute,
){
this.route.params.subscribe(val => {
this.dataService.getData().subscribe(res => this.data = response);
});
}
页面 B
在Page B
,我正在执行按钮操作以路由到Page A
。 有了这个,我期望它在执行此按钮操作时刷新Page A
有人可以帮忙吗?
onSubmit() {
this.router.navigateByUrl('/', {
skipLocationChange: true
}).then(() => {
this.router.navigate(['page-a']);
});
}
此外,我确实将此onSameUrlNavigation
设置为在app-routing.module.ts文件中reload
。
@NgModule({
imports: [
RouterModule.forRoot(routes, {
preloadingStrategy: PreloadAllModules,
onSameUrlNavigation: 'reload'
})
],
exports: [RouterModule]
})
让我们试试这个:
你把你在页面A构造函数中写的代码移动到ngOnInit()然后检查
你将你的代码移动到ionViewDidEnter() 中,它被写入到构造函数(){/ Move this code/ }并尝试将一个页面导航到另一个页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.