angular send data when routing code example
Example 1: pass data through router angular
this.router.navigate(["heroes"], {some-data: "othrData"})
Example 2: pass data in route angular
let navigationExtras: NavigationExtras = {
state: {
user: this.user
}
this.router.navigate(['details'], navigationExtras);
....
constructor(private route: ActivatedRoute, private router: Router) {
this.route.queryParams.subscribe(params => {
if (this.router.getCurrentNavigation().extras.state) {
this.data = this.router.getCurrentNavigation().extras.state.user;
}
});
}
}
.....