'passing value via navigateByUrl with navigationExtras empty
Hi i have a function that navigate to another page and passing a id to another component but it return nothing to the other component. Not sure what i am doing wrong could someone point me in the right direction.
gotoConsulting(questionId: number): void {
let navigationExtras: NavigationExtras = {
queryParams: { 'origine': questionId.toString },
fragment: 'anchor'
};
console.log("idquestion" + questionId);
this._router.navigateByUrl('/consulting',navigationExtras);
}
here the component that get redirect but always return in the view None
export class PageConsulting implements OnInit {
origine: Observable<string>;
constructor(private route: ActivatedRoute) {}
ngOnInit(): void {
this.origine = this.route
.queryParamMap
.map(params => params.get('origine') || 'None');
}
}
Solution 1:[1]
Using the navigate() function appears to cause issues with routes that use the !# prefix in Angular
Solution 2:[2]
You should use this.router.navigate([redirect], navigationExtras); instead of navigateByUrl.
Only navigate have the parameter navigationExtras.
You can refer to angular website below:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
