1import { Component } from '@angular/core';
2import { Router, Event, NavigationStart, NavigationEnd, NavigationError } from '@angular/router';
3
4@Component({
5 selector: 'app-root',
6 template: `<router-outlet></router-outlet>`
7})
8export class AppComponent {
9
10 constructor(private router: Router) {
11
12 this.router.events.subscribe((event: Event) => {
13 if (event instanceof NavigationStart) {
14 // Show loading indicator
15 }
16
17 if (event instanceof NavigationEnd) {
18 // Hide loading indicator
19 }
20
21 if (event instanceof NavigationError) {
22 // Hide loading indicator
23
24 // Present error to user
25 console.log(event.error);
26 }
27 });
28
29 }
30}