I have a situation with my angular 7 Ionic application. When I navigate to a page, I use the following code snippet:
navigateToDetail(entity: User) {
const navigationExtras: NavigationExtras = {
state: {
entity,
entityId: entity.id
}
};
this.router.navigate([RouteNames.users, entity.id], navigationExtras);
}
On my detail-page-base, I retrieve the routing parameters as shown below:
constructor(protected route: ActivatedRoute, protected router: Router, protected baseProvider: ApiResourceBaseService<T>) {
this.route.queryParams.subscribe(params => {
if (this.router.getCurrentNavigation().extras.state) {
this.entity = this.router.getCurrentNavigation().extras.state.entity;
}
});
}
While this setup works fine under normal circumstances, I encounter an issue where the parameters become empty when navigating back using the browser and then navigating forward again.
What would be the best approach to handle navigation in angular 7 in such scenarios?