Skip to content

Commit ec39794

Browse files
committed
feat: route loading indicator
1 parent 3ead0a7 commit ec39794

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/app/app.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
</nav>
6060

6161
<div class="router-outline-container">
62+
<div *ngIf="routeLoading$ | async" class="route-loading"></div>
6263
<router-outlet></router-outlet>
6364
</div>
6465

src/app/app.component.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ nav.top-nav {
6868
}
6969

7070
.router-outline-container {
71+
position: relative;
7172
z-index: 1;
7273
flex: 1;
7374
display: flex;
@@ -88,3 +89,14 @@ footer {
8889
display: flex;
8990
flex-direction: column;
9091
}
92+
93+
.route-loading {
94+
position: absolute;
95+
top: 0;
96+
left: 0;
97+
right: 0;
98+
bottom: 0;
99+
opacity: 0.85;
100+
background-color: var(--color-bg);
101+
z-index: 9999;
102+
}

src/app/app.component.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ import {
88
ViewChild,
99
ViewChildren,
1010
} from '@angular/core';
11-
import {NavigationEnd, Router} from '@angular/router';
11+
import {
12+
NavigationStart,
13+
NavigationEnd,
14+
NavigationError,
15+
NavigationCancel,
16+
Router,
17+
} from '@angular/router';
18+
import {Observable} from 'rxjs';
19+
import {map, filter} from 'rxjs/operators';
1220
import {SearchMeta} from '../search/search-meta.service';
1321

1422
import {ServiceWorkerService} from './service-worker.service';
@@ -31,6 +39,8 @@ export class AppComponent {
3139
@ViewChildren(AppNavItem)
3240
navItems!: QueryList<AppNavItem>;
3341

42+
routeLoading$: Observable<boolean>;
43+
3444
constructor(
3545
private swService: ServiceWorkerService,
3646
searchMeta: SearchMeta,
@@ -39,6 +49,7 @@ export class AppComponent {
3949
this.swService.launchUpdateCheckingRoutine();
4050

4151
router.events.subscribe(routerEvent => {
52+
console.log(routerEvent);
4253
if (routerEvent instanceof NavigationEnd) {
4354
if (this.mobileMenuToggle) {
4455
this.mobileMenuToggle.nativeElement.checked = false;
@@ -49,6 +60,17 @@ export class AppComponent {
4960
}
5061
}
5162
});
63+
64+
this.routeLoading$ = router.events.pipe(
65+
filter(
66+
ev =>
67+
ev instanceof NavigationStart ||
68+
ev instanceof NavigationEnd ||
69+
ev instanceof NavigationCancel ||
70+
ev instanceof NavigationError,
71+
),
72+
map(ev => ev instanceof NavigationStart),
73+
);
5274
}
5375

5476
@HostListener('window:keydown', ['$event'])

0 commit comments

Comments
 (0)