Angular · Junior · Question 44 of 75
How do you navigate from code, for example after saving a form?
- ✓Correct answer:
inject(Router).navigate(['/users', id]) - 2
window.location.href = '/users/' + idis the recommended way - 3
this.routerLink = '/users'
Explanation
Router.navigate takes an array of segments; navigateByUrl takes a string. Both keep the application state, unlike changing location.href.