mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 18:54:11 +08:00
refactor(angular): unused subscription in routerlink (#24950)
This commit is contained in:
@ -1,17 +1,14 @@
|
|||||||
import { LocationStrategy } from '@angular/common';
|
import { LocationStrategy } from '@angular/common';
|
||||||
import { ElementRef, OnChanges, OnDestroy, OnInit, Directive, HostListener, Input, Optional } from '@angular/core';
|
import { ElementRef, OnChanges, OnInit, Directive, HostListener, Input, Optional } from '@angular/core';
|
||||||
import { Router, RouterLink } from '@angular/router';
|
import { Router, RouterLink } from '@angular/router';
|
||||||
import { AnimationBuilder, RouterDirection } from '@ionic/core';
|
import { AnimationBuilder, RouterDirection } from '@ionic/core';
|
||||||
import { Subscription } from 'rxjs';
|
|
||||||
|
|
||||||
import { NavController } from '../../providers/nav-controller';
|
import { NavController } from '../../providers/nav-controller';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[routerLink]',
|
selector: '[routerLink]',
|
||||||
})
|
})
|
||||||
export class RouterLinkDelegateDirective implements OnInit, OnChanges, OnDestroy {
|
export class RouterLinkDelegateDirective implements OnInit, OnChanges {
|
||||||
private subscription?: Subscription;
|
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
routerDirection: RouterDirection = 'forward';
|
routerDirection: RouterDirection = 'forward';
|
||||||
|
|
||||||
@ -34,12 +31,6 @@ export class RouterLinkDelegateDirective implements OnInit, OnChanges, OnDestroy
|
|||||||
this.updateTargetUrlAndHref();
|
this.updateTargetUrlAndHref();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
|
||||||
if (this.subscription) {
|
|
||||||
this.subscription.unsubscribe();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateTargetUrlAndHref() {
|
private updateTargetUrlAndHref() {
|
||||||
if (this.routerLink?.urlTree) {
|
if (this.routerLink?.urlTree) {
|
||||||
const href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.routerLink.urlTree));
|
const href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.routerLink.urlTree));
|
||||||
|
Reference in New Issue
Block a user