1

The situation I have is the following: I have an app in which I have several screens, in one of them I have a list of articles, when clicking on an item it takes me to another screen where the detail of that item is shown, this is the route code:

this.navCtrl.navigateForward('/main/item-detalle', { animated: true, queryParams: {item} });

In the detail screen I have a button to delete the item, when the item is deleted, the user is redirected back to the list of items screen:

this._route.navigate(['/main/home/items'], { replaceUrl: true, queryParams: { itemId: id } });

In this code I send you by parameters the ID of the deleted item to be able to remove it from the items page.

But I can't read what I send by parameters in the URL because the constructor and the ngOnInit are not rerun because the items page was not destroyed.

The idea is not to destroy the items page using "replaceUrl: true".

The application uses Ionic with angular.

1 Answers1

3

Try this solution to access params in a route.

import { ActivatedRoute, Params, Router } from '@angular/router';

constructor(private activatedRoute: ActivatedRoute) {}
this.activatedRoute.parent.params.subscribe(
      (params: Params) => {
        if(params['itemId']) {
         console.log(params['itemId']);
        }
      }
    );
}

Alternatively, you could use a service to share information between components.

Pi314
  • 54
  • 1