From 499054bd6d425e29d91cb5c75ac9069a7e170a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Wed, 18 Dec 2024 14:50:36 +0100 Subject: [PATCH] Fix Route Active Indicator --- src/app/header/header.component.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts index 797339b..ca4d3b9 100644 --- a/src/app/header/header.component.ts +++ b/src/app/header/header.component.ts @@ -3,6 +3,7 @@ import {MatAnchor, MatButton} from '@angular/material/button'; import {MatIcon} from '@angular/material/icon'; import {MatToolbar} from '@angular/material/toolbar'; import {Router, RouterLink} from '@angular/router'; +import {Location} from "@angular/common"; @Component({ selector: 'app-header', @@ -20,7 +21,8 @@ export class HeaderComponent implements OnInit { routes: Array<{ path: string, title: string, class: string }> = []; constructor( - private router: Router + private router: Router, + private location: Location ) { } @@ -31,7 +33,7 @@ export class HeaderComponent implements OnInit { .map(route => ({ path: `/${route.path}`, title: route.title as string, - class: `/${route.path}` == this.router.url ? 'active' : '' + class: `/${route.path}` == (this.location.path() || "/") ? 'active' : '' })); } }