11import { Component , EventEmitter , Input , OnDestroy , OnInit , Output } from '@angular/core' ;
2- import { SidebarNavHelper } from '../app-sidebar-nav.service' ;
32import { NavigationEnd , Router } from '@angular/router' ;
43import { Observable , Subscription } from 'rxjs' ;
54import { filter } from 'rxjs/operators' ;
65
6+ import { SidebarNavHelper } from '../app-sidebar-nav.service' ;
7+ import { INavData } from '../app-sidebar-nav' ;
8+
79@Component ( {
810 selector : 'app-sidebar-nav-link-content, cui-sidebar-nav-link-content' ,
911 template : `
@@ -30,13 +32,13 @@ export class AppSidebarNavLinkContentComponent {
3032} )
3133export class AppSidebarNavLinkComponent implements OnInit , OnDestroy {
3234
33- protected _item : any ;
35+ protected _item : INavData ;
3436
3537 @Input ( )
36- set item ( item : any ) {
38+ set item ( item : INavData ) {
3739 this . _item = JSON . parse ( JSON . stringify ( item ) ) ;
3840 }
39- get item ( ) : any {
41+ get item ( ) : INavData {
4042 return this . _item ;
4143 }
4244
@@ -45,6 +47,7 @@ export class AppSidebarNavLinkComponent implements OnInit, OnDestroy {
4547 public linkType : string ;
4648 public href : string ;
4749 public linkActive : boolean ;
50+ private url : string ;
4851
4952 private navigationEndObservable : Observable < NavigationEnd > ;
5053 private navSubscription : Subscription ;
@@ -60,12 +63,13 @@ export class AppSidebarNavLinkComponent implements OnInit, OnDestroy {
6063 }
6164
6265 ngOnInit ( ) {
66+ this . url = typeof this . item . url === 'string' ? this . item . url : this . router . serializeUrl ( this . router . createUrlTree ( this . item . url ) ) ;
6367 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 ] ;
6670 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 ( '/' ) ;
6973 this . linkActive = itemUrlArray . every ( ( value , index ) => value === urlArray [ index ] ) ;
7074 } ) ;
7175 }
@@ -83,8 +87,7 @@ export class AppSidebarNavLinkComponent implements OnInit, OnDestroy {
8387 }
8488
8589 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' ;
8891 }
8992
9093 linkClicked ( ) {
0 commit comments