1
1
import { Component , EventEmitter , Input , OnDestroy , OnInit , Output } from '@angular/core' ;
2
- import { SidebarNavHelper } from '../app-sidebar-nav.service' ;
3
2
import { NavigationEnd , Router } from '@angular/router' ;
4
3
import { Observable , Subscription } from 'rxjs' ;
5
4
import { filter } from 'rxjs/operators' ;
6
5
6
+ import { SidebarNavHelper } from '../app-sidebar-nav.service' ;
7
+ import { INavData } from '../app-sidebar-nav' ;
8
+
7
9
@Component ( {
8
10
selector : 'app-sidebar-nav-link-content, cui-sidebar-nav-link-content' ,
9
11
template : `
@@ -30,13 +32,13 @@ export class AppSidebarNavLinkContentComponent {
30
32
} )
31
33
export class AppSidebarNavLinkComponent implements OnInit , OnDestroy {
32
34
33
- protected _item : any ;
35
+ protected _item : INavData ;
34
36
35
37
@Input ( )
36
- set item ( item : any ) {
38
+ set item ( item : INavData ) {
37
39
this . _item = JSON . parse ( JSON . stringify ( item ) ) ;
38
40
}
39
- get item ( ) : any {
41
+ get item ( ) : INavData {
40
42
return this . _item ;
41
43
}
42
44
@@ -45,6 +47,7 @@ export class AppSidebarNavLinkComponent implements OnInit, OnDestroy {
45
47
public linkType : string ;
46
48
public href : string ;
47
49
public linkActive : boolean ;
50
+ private url : string ;
48
51
49
52
private navigationEndObservable : Observable < NavigationEnd > ;
50
53
private navSubscription : Subscription ;
@@ -60,12 +63,13 @@ export class AppSidebarNavLinkComponent implements OnInit, OnDestroy {
60
63
}
61
64
62
65
ngOnInit ( ) {
66
+ this . url = typeof this . item . url === 'string' ? this . item . url : this . router . serializeUrl ( this . router . createUrlTree ( this . item . url ) ) ;
63
67
this . linkType = this . getLinkType ( ) ;
64
- this . href = this . isDisabled ( ) ? '' : ( this . item . href || this . item . url ) ;
65
- this . linkActive = this . router . url . split ( / [ ? # ( ] / ) [ 0 ] === this . item . url . split ( / [ ? # ( ] / ) [ 0 ] ;
68
+ this . href = this . isDisabled ( ) ? '' : ( this . item . href || this . url ) ;
69
+ this . linkActive = this . router . url . split ( / [ ? # ( ; ] / ) [ 0 ] === this . href . split ( / [ ? # ( ; ] / ) [ 0 ] ;
66
70
this . navSubscription = this . navigationEndObservable . subscribe ( event => {
67
- const itemUrlArray = this . item . url . split ( / [ ? # ( ] / ) [ 0 ] . split ( '/' ) ;
68
- const urlArray = event . urlAfterRedirects . split ( / [ ? # ( ] / ) [ 0 ] . split ( '/' ) ;
71
+ const itemUrlArray = this . href . split ( / [ ? # ( ; ] / ) [ 0 ] . split ( '/' ) ;
72
+ const urlArray = event . urlAfterRedirects . split ( / [ ? # ( ; ] / ) [ 0 ] . split ( '/' ) ;
69
73
this . linkActive = itemUrlArray . every ( ( value , index ) => value === urlArray [ index ] ) ;
70
74
} ) ;
71
75
}
@@ -83,8 +87,7 @@ export class AppSidebarNavLinkComponent implements OnInit, OnDestroy {
83
87
}
84
88
85
89
public isExternalLink ( ) {
86
- const linkPath = Array . isArray ( this . item . url ) ? this . item . url [ 0 ] : this . item . url ;
87
- return ! ! this . item . href || linkPath . substring ( 0 , 4 ) === 'http' ;
90
+ return ! ! this . item . href || this . url . substring ( 0 , 4 ) === 'http' ;
88
91
}
89
92
90
93
linkClicked ( ) {
0 commit comments