1- import { Directive , HostListener , Input } from '@angular/core' ;
1+ import { Directive , Input , ElementRef , NgZone } from '@angular/core' ;
22import { NavigationExtras } from '@angular/router' ;
33import { ActivatedRoute , Router , UrlTree } from '@angular/router' ;
44import { NavigationTransition } from '@nativescript/core' ;
@@ -52,7 +52,30 @@ export class NSRouterLink {
5252
5353 private commands : any [ ] = [ ] ;
5454
55- constructor ( private router : Router , private navigator : RouterExtensions , private route : ActivatedRoute ) { }
55+ constructor ( private ngZone : NgZone , private router : Router , private navigator : RouterExtensions , private route : ActivatedRoute , private el : ElementRef ) {
56+ }
57+
58+ ngAfterViewInit ( ) {
59+ this . el . nativeElement . on ( 'tap' , ( ) => {
60+ this . ngZone . run ( ( ) => {
61+ if ( NativeScriptDebug . isLogEnabled ( ) ) {
62+ NativeScriptDebug . routerLog ( `nsRouterLink.tapped: ${ this . commands } ` + `clear: ${ this . clearHistory } ` + `transition: ${ JSON . stringify ( this . pageTransition ) } ` + `duration: ${ this . pageTransitionDuration } ` ) ;
63+ }
64+
65+ const extras = this . getExtras ( ) ;
66+ // this.navigator.navigateByUrl(this.urlTree, extras);
67+ this . navigator . navigate ( this . commands , {
68+ ...extras ,
69+ relativeTo : this . route ,
70+ queryParams : this . queryParams ,
71+ fragment : this . fragment ,
72+ preserveQueryParams : attrBoolValue ( this . preserveQueryParams ) ,
73+ queryParamsHandling : this . queryParamsHandling ,
74+ preserveFragment : attrBoolValue ( this . preserveFragment ) ,
75+ } ) ;
76+ } ) ;
77+ } ) ;
78+ }
5679
5780 @Input ( 'nsRouterLink' )
5881 set params ( data : any [ ] | string ) {
@@ -63,16 +86,6 @@ export class NSRouterLink {
6386 }
6487 }
6588
66- @HostListener ( 'tap' )
67- onTap ( ) {
68- if ( NativeScriptDebug . isLogEnabled ( ) ) {
69- NativeScriptDebug . routerLog ( `nsRouterLink.tapped: ${ this . commands } ` + `clear: ${ this . clearHistory } ` + `transition: ${ JSON . stringify ( this . pageTransition ) } ` + `duration: ${ this . pageTransitionDuration } ` ) ;
70- }
71-
72- const extras = this . getExtras ( ) ;
73- this . navigator . navigateByUrl ( this . urlTree , extras ) ;
74- }
75-
7689 private getExtras ( ) : NavigationExtras & NavigationOptions {
7790 const transition = this . getTransition ( ) ;
7891 return {
0 commit comments