11import { AccordionComponent } from './accordion.component' ;
2- import { Component , ViewEncapsulation , HostBinding , ViewChild , HostListener } from '@angular/core' ;
2+ import { Component , ViewEncapsulation , HostBinding , ViewChild , HostListener , SimpleChanges , OnChanges } from '@angular/core' ;
33import { AccordionBaseLinkComponent } from './accordion-base-link-component.class' ;
4- import { RouterLinkActive , Router } from '@angular/router' ;
4+ import { RouterLinkActive , Router , UrlTree , Params } from '@angular/router' ;
55
66@Component ( {
77 selector : 'd-accordion-item-routerlink' ,
88 templateUrl : './accordion-item-routerlink.component.html' ,
99 encapsulation : ViewEncapsulation . None ,
1010} )
11- export class AccordionItemRouterlinkComponent extends AccordionBaseLinkComponent {
12- @ViewChild ( RouterLinkActive , { static : false } ) routerLinkActiveDirective : RouterLinkActive ;
11+ export class AccordionItemRouterlinkComponent extends AccordionBaseLinkComponent implements OnChanges {
12+ @ViewChild ( RouterLinkActive ) routerLinkActiveDirective : RouterLinkActive ;
1313 @HostBinding ( 'class.devui-router-active' )
1414 get routerLinkActived ( ) : boolean {
1515 return ! ! ( this . routerLinkActiveDirective && this . routerLinkActiveDirective . isActive ) ;
1616 }
17+ private set urlTree ( urlTree : UrlTree ) {
18+ if ( urlTree ) {
19+ this . queryParams = urlTree . queryParams ;
20+ this . fragment = urlTree . fragment ;
21+ } else {
22+ this . queryParams = undefined ;
23+ this . fragment = undefined ;
24+ }
25+ }
26+
27+ public path : string ;
28+ public queryParams : Params ;
29+ public fragment : string ;
1730
1831 constructor ( protected accordion : AccordionComponent , private router : Router ) {
1932 super ( accordion ) ;
@@ -29,4 +42,24 @@ export class AccordionItemRouterlinkComponent extends AccordionBaseLinkComponent
2942 } ) ;
3043 }
3144 }
45+
46+ ngOnChanges ( changes : SimpleChanges ) : void {
47+ if ( changes [ 'item' ] ) {
48+ if ( this . link ) {
49+ this . urlTree = this . router . parseUrl ( this . link ) ;
50+ const handelPath = ( url : string ) => {
51+ let path = url ;
52+ const index = url . indexOf ( '?' ) ;
53+ if ( index > - 1 ) {
54+ path = url . slice ( 0 , index ) ;
55+ }
56+ return path ;
57+ } ;
58+ this . path = handelPath ( this . link ) ;
59+ } else {
60+ this . urlTree = undefined ;
61+ this . path = undefined ;
62+ }
63+ }
64+ }
3265}
0 commit comments