Loading

Quipoin Menu

Learn • Practice • Grow

angular / Router Outlet and Navigation
interview

Q1. How do you create navigation links in Angular?
Use the RouterLink directive instead of href.
Example:
Users
User Detail
RouterLink prevents full page reloads and works with Angular''s router.

Q2. What is RouterLinkActive?
RouterLinkActive adds CSS classes to an element when the associated route is active.
Useful for highlighting current navigation.
Example:
Users
The ''active'' class is applied when the URL matches.

Q3. How do you navigate programmatically?
Inject the Router service and use navigate or navigateByUrl.
Example:
constructor(private router: Router) {}
goToUsers() { this.router.navigate([''/users'']); }
goToUser(id) { this.router.navigate([''/users'', id]); }

Q4. What is the difference between navigate and navigateByUrl?
navigate uses an array of path segments and optional query parameters.
navigateByUrl takes a complete URL string.
navigate is more flexible for dynamic parameters.
Example: navigate([''/users'', id]) vs navigateByUrl(''/users/'' + id).

Q5. How do you pass query parameters and fragments?
With routerLink:
Users
Programmatically:
this.router.navigate([''/users''], { queryParams: { page: 1 }, fragment: ''top'' });