router.navigate pass data angular 9 code example

Example 1: pass data through router angular

this.router.navigate(["heroes"], {some-data: "othrData"})

Example 2: pass data in route angular

// Send user data
let navigationExtras: NavigationExtras = {
	state: {
    user: this.user
}

this.router.navigate(['details'], navigationExtras);

// Acess data in details page
....
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;
      	}
    	});
  	}
}
.....