</>
Skip to content
Angular lessons (24/43)

Angular — Navigation

RouterLink

<a routerLink="/home">Home</a>
<a [routerLink]="['/user', userId]">Profile</a>

RouterLinkActive

<a routerLink="/home" routerLinkActive="active">Home</a>
<a routerLink="/about" routerLinkActive="active">About</a>

Programmatic Navigation

import { Router } from '@angular/router';

@Component({ ... })
export class MyComponent {
  constructor(private router: Router) {}
  
  navigate() {
    this.router.navigate(['/user', 123]);
  }
  
  navigateWithQuery() {
    this.router.navigate(['/search'], { 
      queryParams: { q: 'angular' } 
    });
  }
}

Route Events

import { Router, NavigationEnd } from '@angular/router';

constructor(private router: Router) {
  this.router.events.subscribe(event => {
    if (event instanceof NavigationEnd) {
      console.log('Navigated to:', event.url);
    }
  });
}

Relative Navigation

// Navigate relative to current route
this.router.navigate(['../sibling'], { relativeTo: this.route });

Mini Practice

  1. Use routerLink
  2. Highlight active routes
  3. Navigate programmatically
  4. Listen to route events

Up Next

Continue with API Calls — making HTTP requests.

Related Topics

Frequently Asked Questions about Navigation

What is Navigation in Angular?

Navigation is a fundamental concept in Angular. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Navigation?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Navigation.

Why is Navigation important in Angular?

Navigation is essential for Angular development. Understanding this concept will help you write better code and solve real-world problems more effectively.