Fix Route Active Indicator
This commit is contained in:
parent
2e9ec6e433
commit
499054bd6d
1 changed files with 4 additions and 2 deletions
|
@ -3,6 +3,7 @@ import {MatAnchor, MatButton} from '@angular/material/button';
|
||||||
import {MatIcon} from '@angular/material/icon';
|
import {MatIcon} from '@angular/material/icon';
|
||||||
import {MatToolbar} from '@angular/material/toolbar';
|
import {MatToolbar} from '@angular/material/toolbar';
|
||||||
import {Router, RouterLink} from '@angular/router';
|
import {Router, RouterLink} from '@angular/router';
|
||||||
|
import {Location} from "@angular/common";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-header',
|
selector: 'app-header',
|
||||||
|
@ -20,7 +21,8 @@ export class HeaderComponent implements OnInit {
|
||||||
routes: Array<{ path: string, title: string, class: string }> = [];
|
routes: Array<{ path: string, title: string, class: string }> = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router
|
private router: Router,
|
||||||
|
private location: Location
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +33,7 @@ export class HeaderComponent implements OnInit {
|
||||||
.map(route => ({
|
.map(route => ({
|
||||||
path: `/${route.path}`,
|
path: `/${route.path}`,
|
||||||
title: route.title as string,
|
title: route.title as string,
|
||||||
class: `/${route.path}` == this.router.url ? 'active' : ''
|
class: `/${route.path}` == (this.location.path() || "/") ? 'active' : ''
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue