mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 18:17:31 +08:00
fix(angular): back-button
This commit is contained in:
@ -1,12 +1,16 @@
|
|||||||
import { Directive, HostListener, Optional } from '@angular/core';
|
import { Directive, HostListener, Input, Optional } from '@angular/core';
|
||||||
import { IonRouterOutlet } from './ion-router-outlet';
|
import { IonRouterOutlet } from './ion-router-outlet';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: 'ion-back-button'
|
selector: 'ion-back-button'
|
||||||
})
|
})
|
||||||
export class IonBackButton {
|
export class IonBackButton {
|
||||||
|
|
||||||
|
@Input() defaultHref: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@Optional() private router: Router,
|
||||||
@Optional() private routerOutlet: IonRouterOutlet,
|
@Optional() private routerOutlet: IonRouterOutlet,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@ -14,6 +18,8 @@ export class IonBackButton {
|
|||||||
onClick() {
|
onClick() {
|
||||||
if (this.routerOutlet && this.routerOutlet.canGoBack()) {
|
if (this.routerOutlet && this.routerOutlet.canGoBack()) {
|
||||||
this.routerOutlet.pop();
|
this.routerOutlet.pop();
|
||||||
|
} else if (this.router && this.defaultHref != null) {
|
||||||
|
this.router.navigateByUrl(this.defaultHref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
import { ComponentRef } from '@angular/core';
|
|
||||||
|
|
||||||
export function runTransition(enteringRef: ComponentRef<any>, leavingRef: ComponentRef<any>): Promise<void> {
|
|
||||||
const enteringElm = (enteringRef && enteringRef.location && enteringRef.location.nativeElement);
|
|
||||||
const leavingElm = (leavingRef && leavingRef.location && leavingRef.location.nativeElement);
|
|
||||||
|
|
||||||
if (!enteringElm && !leavingElm) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
return tr(enteringElm, leavingElm);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function tr(enteringElm: HTMLElement, leavingElm: HTMLElement): Promise<void> {
|
|
||||||
console.log('transition start');
|
|
||||||
|
|
||||||
return new Promise(resolve => {
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
|
|
||||||
if (enteringElm) {
|
|
||||||
enteringElm.classList.add('show-page');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (leavingElm) {
|
|
||||||
leavingElm.classList.remove('show-page');
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve();
|
|
||||||
}, 750);
|
|
||||||
});
|
|
||||||
}
|
|
Reference in New Issue
Block a user