|
1 | 1 | import {Directive, HostBinding, HostListener, Input} from '@angular/core';
|
2 | 2 | import {LocationStrategy} from '@angular/common';
|
3 | 3 | import {Router, ActivatedRoute, UrlTree} from '@angular/router';
|
| 4 | +import {routerLog} from "../trace"; |
4 | 5 |
|
5 | 6 | /**
|
6 | 7 | * The RouterLink directive lets you link to specific parts of your app.
|
@@ -34,43 +35,25 @@ export class NSRouterLink {
|
34 | 35 | @Input() queryParams: { [k: string]: any };
|
35 | 36 | @Input() fragment: string;
|
36 | 37 |
|
37 |
| - // the url displayed on the anchor element. |
38 |
| - // @HostBinding() href: string; |
39 |
| - |
40 |
| - urlTree: UrlTree; |
41 |
| - |
42 | 38 | /**
|
43 | 39 | * @internal
|
44 | 40 | */
|
45 |
| - constructor( |
46 |
| - private router: Router, private route: ActivatedRoute, |
47 |
| - private locationStrategy: LocationStrategy) { } |
| 41 | + constructor(private router: Router, private route: ActivatedRoute) { } |
48 | 42 |
|
49 | 43 | @Input("nsRouterLink")
|
50 | 44 | set params(data: any[] | string) {
|
51 | 45 | if (Array.isArray(data)) {
|
52 |
| - this.commands = <any>data; |
| 46 | + this.commands = data; |
53 | 47 | } else {
|
54 | 48 | this.commands = [data];
|
55 | 49 | }
|
56 | 50 | }
|
57 | 51 |
|
58 |
| - ngOnChanges(changes: {}): any { this.updateTargetUrlAndHref(); } |
59 |
| - |
60 | 52 | @HostListener("tap")
|
61 | 53 | onTap() {
|
62 |
| - if (this.urlTree) { |
63 |
| - this.router.navigateByUrl(this.urlTree); |
64 |
| - } |
65 |
| - } |
66 |
| - |
67 |
| - private updateTargetUrlAndHref(): void { |
68 |
| - this.urlTree = this.router.createUrlTree( |
| 54 | + routerLog("nsRouterLink.tapped: " + this.commands); |
| 55 | + this.router.navigate( |
69 | 56 | this.commands,
|
70 | 57 | { relativeTo: this.route, queryParams: this.queryParams, fragment: this.fragment });
|
71 |
| - |
72 |
| - // if (this.urlTree) { |
73 |
| - // this.href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.urlTree)); |
74 |
| - // } |
75 | 58 | }
|
76 | 59 | }
|
0 commit comments