I am facing an issue with 2 navigation points leading to the same screen
1.
this.router.navigate([this.config.AppTree.App.Module.Details.Path], { state: { data: { id: this.TableId } } });
this.router.navigate([this.config.AppTree.App.Module.Details.Path], { state: { data: { id: id } } });
Although the correct ID value is being sent, there seems to be a difference in the data type of the parameter in both cases
The current solution works but it is not elegant:
let params = history.state.data;
if (typeof (params.id) == 'object') { this.TableId = parseInt(params.id[0]); }
else { this.TableId = params.id; }
I am looking for a better way to send or receive the parameter. Why does it get added into an array in one case? Is there a parsing method that could make it cleaner and possibly eliminate the need for the if
statement?
UPDATE:
definition:
TableId: number;
I tried
this.id = this.route.snapshot.paramMap.get('state')
suggested by Mark Homer. I have
import { Router, ActivatedRoute } from '@angular/router';
and also added it to the constructor, however, using either snapshot
or paramMap
, I still encounter the error
Property does not exist on type ...
. Is there something crucial that I am overlooking?