angular navigate using component
//ng new routing-app --routing
//ng generate component first
//ng generate component second
import { Router } from '@angular/router';
...
export class AboutUserComponent implements OnInit {
user: User;
constructor(
private route: ActivatedRoute,
private service: UserService,
private router: Router
) {}
ngOnInit() {
// grab the current username
let username = this.route.snapshot.params['username'];
this.service.getUser(username).then(user => this.user = user);
}
goBack() {
this.router.navigate(['/about']);
}
}