On the page you will receive the parameters both by routerLink
and navigate
you can make a logic to see where it came from.
Ex:
Using routerLink
you pass the parameter this way:
idPagina1 = this.route.snapshot.params['id'];
Using navigate
you get within ngOnInit
this way:
ngOnInit(){
this.route.queryParams.subscribe(
(queryParams: any) => {
this.idPagina2 = queryParams['id'];
});
}
So you can use a global variable where if the parameter comes from page 1 the idPage1 will be different from null
, or if it comes from page 2 the idPage2 will be different from null
. So you can check the parameter like this:
id: number;
ngOnInit(){
if(this.idPagina1 != null){
id = this.idPagina1;
}else{
this.route.queryParams.subscribe(
(queryParams: any) => {
this.idPagina2 = queryParams['id'];
id = this.idPagina2;
});
}
}
I do not know if you are using parameters, but I believe you are trying to come up with different parameters from different to to access a common page. It is? In case I think it helps you.